Skip to content

Commit

Permalink
[10.x] Throw timeoutException instead of maxAttemptsExceededException…
Browse files Browse the repository at this point in the history
… when a job times out (laravel#46968)

* Throw timeoutException instead of maxAttemptsExceededException when a job times out

* formatting

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
2 people authored and milwad-dev committed May 12, 2023
1 parent d1e7609 commit d1af834
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/Illuminate/Queue/TimeoutExceededException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Illuminate\Queue;

class TimeoutExceededException extends MaxAttemptsExceededException
{
//
}
17 changes: 15 additions & 2 deletions src/Illuminate/Queue/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ protected function registerTimeoutHandler($job, WorkerOptions $options)
pcntl_signal(SIGALRM, function () use ($job, $options) {
if ($job) {
$this->markJobAsFailedIfWillExceedMaxAttempts(
$job->getConnectionName(), $job, (int) $options->maxTries, $e = $this->maxAttemptsExceededException($job)
$job->getConnectionName(), $job, (int) $options->maxTries, $e = $this->timoutExceededException($job)
);

$this->markJobAsFailedIfWillExceedMaxExceptions(
Expand Down Expand Up @@ -778,7 +778,20 @@ public function kill($status = 0, $options = null)
protected function maxAttemptsExceededException($job)
{
return new MaxAttemptsExceededException(
$job->resolveName().' has been attempted too many times or run too long. The job may have previously timed out.'
$job->resolveName().' has been attempted too many times.'
);
}

/**
* Create an instance of TimeoutExceededException.
*
* @param \Illuminate\Contracts\Queue\Job $job
* @return \Illuminate\Queue\TimeoutExceededException
*/
protected function timoutExceededException($job)
{
return new TimeoutExceededException(
$job->resolveName().' has timed out.'
);
}

Expand Down

0 comments on commit d1af834

Please sign in to comment.