From 2c2c28dff4b0f8632f74ca1945f830fb462c6b56 Mon Sep 17 00:00:00 2001 From: Namoshek Date: Tue, 22 Feb 2022 21:56:51 +0100 Subject: [PATCH] Forget job timer in case of exception or failed job (#1127) * Forget job timer in case of exception or failed job * Remove trailing whitespace --- src/EventMap.php | 5 +++++ src/Listeners/ForgetJobTimer.php | 37 ++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/Listeners/ForgetJobTimer.php diff --git a/src/EventMap.php b/src/EventMap.php index 4ad26978..0a684b7c 100644 --- a/src/EventMap.php +++ b/src/EventMap.php @@ -33,7 +33,12 @@ trait EventMap Listeners\MarkJobsAsMigrated::class, ], + \Illuminate\Queue\Events\JobExceptionOccurred::class => [ + Listeners\ForgetJobTimer::class, + ], + \Illuminate\Queue\Events\JobFailed::class => [ + Listeners\ForgetJobTimer::class, Listeners\MarshalFailedEvent::class, ], diff --git a/src/Listeners/ForgetJobTimer.php b/src/Listeners/ForgetJobTimer.php new file mode 100644 index 00000000..278b4330 --- /dev/null +++ b/src/Listeners/ForgetJobTimer.php @@ -0,0 +1,37 @@ +watch = $watch; + } + + /** + * Handle the event. + * + * @param \Illuminate\Queue\Events\JobExceptionOccurred|\Illuminate\Queue\Events\JobFailed $event + * @return void + */ + public function handle($event) + { + $this->watch->forget($event->job->getJobId()); + } +}