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]); + } }