Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forget job timer in case of exception or failed job #1127

Merged
merged 2 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}