3 months ago

Which class to use "implements ShouldQueue"? notifications v. queue job

Posted 3 months ago by trevorpan

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.

  1. console command via cron job is run
  2. handle() does some logic and fires email notifications
  3. php artisan queue:work redis is 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
	$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;


// 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?

Please sign in or create an account to participate in this conversation.