Laravel - Queues - Monitoring Your Queues

If your queue receives a sudden influx of jobs, it could become overwhelmed, leading to a long wait time for jobs to complete. If you wish, Laravel can alert you when your queue job count exceeds a specified threshold.

To get started, you should schedule the queue:monitor command to run every minute. The command accepts the names of the queues you wish to monitor as well as your desired job count threshold:

    
    php artisan queue:monitor redis:default,redis:deployments --max=100
	

Scheduling this command alone is not enough to trigger a notification alerting you of the queue's overwhelmed status. When the command encounters a queue that has a job count exceeding your threshold, an Illuminate\Queue\Events\QueueBusy event will be dispatched. You may listen for this event within your application's EventServiceProvider in order to send a notification to you or your development team:

    
    use App\Notifications\QueueHasLongWaitTime;
    use Illuminate\Queue\Events\QueueBusy;
    use Illuminate\Support\Facades\Event;
    use Illuminate\Support\Facades\Notification;
    
    /**
     * Register any other events for your application.
     *
     * @return void
     */
    public function boot()
    {
        Event::listen(function (QueueBusy $event) {
            Notification::route('mail', '[email protected]')
                    ->notify(new QueueHasLongWaitTime(
                        $event->connection,
                        $event->queue,
                        $event->size
                    ));
        });
    }