Skip to content

Commit

Permalink
Throw timeoutException instead of maxAttemptsExceededException when a…
Browse files Browse the repository at this point in the history
… job times out
  • Loading branch information
PrinsFrank committed May 5, 2023
1 parent d6ac53d commit 2bd41ee
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/Illuminate/Queue/TimeoutExceededException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Illuminate\Queue;

use RuntimeException;

class TimeoutExceededException extends RuntimeException
{
//
}
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 and was terminated.'
);
}

Expand Down

0 comments on commit 2bd41ee

Please sign in to comment.