Certainly! Laravel Horizon fires the LongQueueDetected notification when a queue is considered "long running" based on your configuration. By default, this notification is sent via mail and Slack, and its content is defined in the Laravel\Horizon\Notifications\LongQueueDetected class.
To customize the content of this notification, you have two main options:
1. Listen for the Event and Send Your Own Notification
Horizon fires the LongQueueDetected event (Laravel\Horizon\Events\LongQueueDetected). You can listen for this event and send your own custom notification.
Example:
- Create a Custom Notification:
php artisan make:notification CustomLongQueueDetected
Edit the generated notification (app/Notifications/CustomLongQueueDetected.php) to customize the content as you wish.
- Register an Event Listener:
In your EventServiceProvider:
protected $listen = [
\Laravel\Horizon\Events\LongQueueDetected::class => [
\App\Listeners\SendCustomLongQueueDetectedNotification::class,
],
];
- Create the Listener:
php artisan make:listener SendCustomLongQueueDetectedNotification
In your listener (app/Listeners/SendCustomLongQueueDetectedNotification.php):
public function handle(\Laravel\Horizon\Events\LongQueueDetected $event)
{
// Send your custom notification to the desired notifiable
\Notification::route('mail', '[email protected]')
->notify(new \App\Notifications\CustomLongQueueDetected($event->connection, $event->queue, $event->size));
}
2. Override the Default Notification (Advanced)
If you want to completely replace the default notification, you would need to fork Horizon or override the notification binding in the service container. This is more advanced and not generally recommended, as the first approach is simpler and more maintainable.
Summary:
The recommended way is to listen for the LongQueueDetected event and send your own custom notification, as shown above. This gives you full control over the notification content and delivery channels.
Let me know if you need a full example of the custom notification class!