diff --git a/src/Contracts/LongWaitDetectedNotification.php b/src/Contracts/LongWaitDetectedNotification.php new file mode 100644 index 00000000..48efa656 --- /dev/null +++ b/src/Contracts/LongWaitDetectedNotification.php @@ -0,0 +1,8 @@ +connection, $this->queue, $this->seconds - ); + return Container::getInstance()->make(LongWaitDetectedNotification::class, [ + 'connection' => $this->connection, + 'queue' => $this->queue, + 'seconds' => $this->seconds, + ]); } } diff --git a/src/Notifications/LongWaitDetected.php b/src/Notifications/LongWaitDetected.php index 5d974c59..f724f777 100644 --- a/src/Notifications/LongWaitDetected.php +++ b/src/Notifications/LongWaitDetected.php @@ -10,9 +10,10 @@ use Illuminate\Notifications\Slack\BlockKit\Blocks\SectionBlock; use Illuminate\Notifications\Slack\SlackMessage as ChannelIdSlackMessage; use Illuminate\Support\Str; +use Laravel\Horizon\Contracts\LongWaitDetectedNotification; use Laravel\Horizon\Horizon; -class LongWaitDetected extends Notification +class LongWaitDetected extends Notification implements LongWaitDetectedNotification { use Queueable; diff --git a/src/ServiceBindings.php b/src/ServiceBindings.php index cff53682..054d08b0 100644 --- a/src/ServiceBindings.php +++ b/src/ServiceBindings.php @@ -27,5 +27,8 @@ trait ServiceBindings Contracts\SupervisorRepository::class => Repositories\RedisSupervisorRepository::class, Contracts\TagRepository::class => Repositories\RedisTagRepository::class, Contracts\WorkloadRepository::class => Repositories\RedisWorkloadRepository::class, + + // Notifications... + Contracts\LongWaitDetectedNotification::class => Notifications\LongWaitDetected::class, ]; } diff --git a/tests/Feature/NotificationOverridesTest.php b/tests/Feature/NotificationOverridesTest.php new file mode 100644 index 00000000..6076d0d6 --- /dev/null +++ b/tests/Feature/NotificationOverridesTest.php @@ -0,0 +1,48 @@ +bind(LongWaitDetectedNotificationContract::class, CustomLongWaitDetectedNotification::class); + + event(new LongWaitDetected('redis', 'test-queue-2', 60)); + + Notification::assertSentOnDemand(CustomLongWaitDetectedNotification::class); + } + + public function test_normal_notifications_are_sent_if_not_specified() + { + Notification::fake(); + + Horizon::routeMailNotificationsTo('taylor@laravel.com'); + + event(new LongWaitDetected('redis', 'test-queue-2', 60)); + + Notification::assertSentOnDemand(LongWaitDetectedNotification::class); + } +} + +class CustomLongWaitDetectedNotification extends LongWaitDetectedNotification implements LongWaitDetectedNotificationContract +{ + public function toMail($notifiable) + { + return (new MailMessage) + ->line('This is a custom notification for a long wait.'); + } +}