Skip to content

Commit

Permalink
[10.x] Add job timeout occurred event (#47068)
Browse files Browse the repository at this point in the history
* feat: add job timeout occurred event

* fix style

* formatting

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
saeedhosseiinii and taylorotwell committed May 16, 2023
1 parent 21a5b6d commit 2d462ff
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/Illuminate/Queue/Events/JobTimedOut.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Illuminate\Queue\Events;

class JobTimedOut
{
/**
* The connection name.
*
* @var string
*/
public $connectionName;

/**
* The job instance.
*
* @var \Illuminate\Contracts\Queue\Job
*/
public $job;

/**
* Create a new event instance.
*
* @param string $connectionName
* @param \Illuminate\Contracts\Queue\Job $job
* @return void
*/
public function __construct($connectionName, $job)
{
$this->job = $job;
$this->connectionName = $connectionName;
}
}
5 changes: 5 additions & 0 deletions src/Illuminate/Queue/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Illuminate\Queue\Events\JobProcessed;
use Illuminate\Queue\Events\JobProcessing;
use Illuminate\Queue\Events\JobReleasedAfterException;
use Illuminate\Queue\Events\JobTimedOut;
use Illuminate\Queue\Events\Looping;
use Illuminate\Queue\Events\WorkerStopping;
use Illuminate\Support\Carbon;
Expand Down Expand Up @@ -223,6 +224,10 @@ protected function registerTimeoutHandler($job, WorkerOptions $options)
$this->markJobAsFailedIfItShouldFailOnTimeout(
$job->getConnectionName(), $job, $e
);

$this->events->dispatch(new JobTimedOut(
$job->getConnectionName(), $job
));
}

$this->kill(static::EXIT_ERROR, $options);
Expand Down

0 comments on commit 2d462ff

Please sign in to comment.