From 69486d5e4fad8b6ee02c97ed0bea39ef241df956 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 21 Feb 2022 13:55:13 -0600 Subject: [PATCH] clear stopwatch once job is deleted --- src/Listeners/UpdateJobMetrics.php | 4 +++- src/Stopwatch.php | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Listeners/UpdateJobMetrics.php b/src/Listeners/UpdateJobMetrics.php index 67e7b4ef..7b8b12f6 100644 --- a/src/Listeners/UpdateJobMetrics.php +++ b/src/Listeners/UpdateJobMetrics.php @@ -47,7 +47,7 @@ public function handle(JobDeleted $event) return; } - $time = $this->watch->check($event->payload->id()); + $time = $this->watch->check($id = $event->payload->id()); $this->metrics->incrementQueue( $event->job->getQueue(), $time @@ -56,5 +56,7 @@ public function handle(JobDeleted $event) $this->metrics->incrementJob( $event->payload->displayName(), $time ); + + $this->watch->forget($id); } } diff --git a/src/Stopwatch.php b/src/Stopwatch.php index 2317b3d4..bfee758f 100644 --- a/src/Stopwatch.php +++ b/src/Stopwatch.php @@ -34,4 +34,15 @@ public function check($key) return round((microtime(true) - $this->timers[$key]) * 1000, 2); } } + + /** + * Forget a given timer. + * + * @param string $key + * @return void + */ + public function forget($key) + { + unset($this->timers[$key]); + } }