Demonstrates laravel queues and demonstrates a notification and reminder system
In .env
QUEUE_CONNECTION=sync
QUEUE_CONNECTION=database
Queues
php artisan queue:table
, php artisan migrate
php artisan queue:work
Jobs
php artisan make:job [jobName]
[jobName]::dispatch([$params])
, also dispatchIf/dispatchUnless->delay(now()->addMinute())
php artisan queue:work --tries=3
or right inside job: public $tries = X
handle()
functionFailed Jobs
php artisan queue:failed-table
, php artisan migrate
Schedules
schedule()
method of App\Console\Kernel class
Can run artisan commands, ex.: $schedule->command('migrate:refresh --seed')->daily();
php artisan schedule:work
php artisan make:mail [mailName] --markdown=emails.etc
Other tips:
Log::info('this is logged')
Notifications:
implements shouldQueue
after making a notification with make:notification
$user->notify(new Notification())
Notification::route('mail', 'email@email.com')->route(etc...)->notify(new Notification())
php artisan notifications:table
- see gotchas (4)To add to the priority queue: dispatch((new Job)->onQueue('priority'));
* see gotchas (1)
Run this worker for this project with Supervisor/CRON:
php artisan queue:work --queue=priority,default --tries=2
-> runs priority queue items first, allows 2 attempts before failing
can run this line locally for development
Twilio (https://github.com/laravel-notification-channels/twilio): composer require laravel-notification-channels/twilio
Enter in .env: TWILIO_ACCOUNT_SID= TWILIO_AUTH_TOKEN= TWILIO_DEBUG_TO= TWILIO_FROM=
php artisan vendor:publish --provider="NotificationChannels\Twilio\TwilioProvider"