@trevorpan If you are using horizon, is there a reason you are using:
php artisan queue:work redis
and not
php artisan horizon ?
Which class to use "implements ShouldQueue"? notifications v. queue job
I've watched the Queue it Up series which is really helpful. However, my queued jobs seem to fail in horizon when using a custom console command.
Here's the steps I'm taking in a Laravel 6 app.
- console command via cron job is run
-
handle()does some logic and fires email notifications -
php artisan queue:work redisis up and running. horizon status is Active.
//queue connection
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => 'default',
'retry_after' => 90,
'block_for' => 5,
],
// console command handle()
//here are the various emails in isolation
logic
...
$lost->user->notify(new SendJobBiddedLosingBiddersNotified($lost));
$winningBid->user->notify(new SendJobBiddedWinningBidderNotified($winningBid));
$biddedJob->user->notify(new SendJobBiddedBuyerNotified($biddedJob));
...
// sample notification class
class SendJobBiddedLosingBiddersNotified extends Notification implements ShouldQueue
{
use InteractsWithQueue, Queueable;
VS.
// queue job class
class SendDeadlineExpiredEmails implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
Should I even use a queue job? Should the console command call a job which then fires notifications?
I queue all of my notifications and jobs. The only items I do not queue are my realtime events that I want broadcasted immediately. The main difference between notification and a job is notification allows specifying multiple channels to send the data on and injects the notifiable model class automatically. I usually use jobs for business logic that does not need to directly notify one person or loops through multiple models to run actions/notification on. I notify for single case uses and house no business logic inside a notification class.
Please or to participate in this conversation.