Skip to content

Commit 476f3b5

Browse files
[10.x] Throw timeoutException instead of maxAttemptsExceededException when a job times out (#46968)
* Throw timeoutException instead of maxAttemptsExceededException when a job times out * formatting --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 40a7d54 commit 476f3b5

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Illuminate\Queue;
4+
5+
class TimeoutExceededException extends MaxAttemptsExceededException
6+
{
7+
//
8+
}

src/Illuminate/Queue/Worker.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ protected function registerTimeoutHandler($job, WorkerOptions $options)
213213
pcntl_signal(SIGALRM, function () use ($job, $options) {
214214
if ($job) {
215215
$this->markJobAsFailedIfWillExceedMaxAttempts(
216-
$job->getConnectionName(), $job, (int) $options->maxTries, $e = $this->maxAttemptsExceededException($job)
216+
$job->getConnectionName(), $job, (int) $options->maxTries, $e = $this->timoutExceededException($job)
217217
);
218218

219219
$this->markJobAsFailedIfWillExceedMaxExceptions(
@@ -778,7 +778,20 @@ public function kill($status = 0, $options = null)
778778
protected function maxAttemptsExceededException($job)
779779
{
780780
return new MaxAttemptsExceededException(
781-
$job->resolveName().' has been attempted too many times or run too long. The job may have previously timed out.'
781+
$job->resolveName().' has been attempted too many times.'
782+
);
783+
}
784+
785+
/**
786+
* Create an instance of TimeoutExceededException.
787+
*
788+
* @param \Illuminate\Contracts\Queue\Job $job
789+
* @return \Illuminate\Queue\TimeoutExceededException
790+
*/
791+
protected function timoutExceededException($job)
792+
{
793+
return new TimeoutExceededException(
794+
$job->resolveName().' has timed out.'
782795
);
783796
}
784797

0 commit comments

Comments
 (0)