Skip to content

Commit

Permalink
clear stopwatch once job is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Feb 21, 2022
1 parent ff534ce commit 69486d5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Listeners/UpdateJobMetrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -56,5 +56,7 @@ public function handle(JobDeleted $event)
$this->metrics->incrementJob(
$event->payload->displayName(), $time
);

$this->watch->forget($id);
}
}
11 changes: 11 additions & 0 deletions src/Stopwatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}

0 comments on commit 69486d5

Please sign in to comment.