Skip to content

Commit

Permalink
Forget job timer in case of exception or failed job (#1127)
Browse files Browse the repository at this point in the history
* Forget job timer in case of exception or failed job

* Remove trailing whitespace
  • Loading branch information
Namoshek authored Feb 22, 2022
1 parent b335df6 commit 2c2c28d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/EventMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],

Expand Down
37 changes: 37 additions & 0 deletions src/Listeners/ForgetJobTimer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Laravel\Horizon\Listeners;

use Laravel\Horizon\Stopwatch;

class ForgetJobTimer
{
/**
* The stopwatch instance.
*
* @var \Laravel\Horizon\Stopwatch
*/
public $watch;

/**
* Create a new listener instance.
*
* @param \Laravel\Horizon\Stopwatch $watch
* @return void
*/
public function __construct(Stopwatch $watch)
{
$this->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());
}
}

0 comments on commit 2c2c28d

Please sign in to comment.