From d1af834f4ffa196d021ee2be7182a5753a413579 Mon Sep 17 00:00:00 2001 From: PrinsFrank <25006490+PrinsFrank@users.noreply.github.com> Date: Mon, 8 May 2023 17:31:28 +0200 Subject: [PATCH] [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 --- .../Queue/TimeoutExceededException.php | 8 ++++++++ src/Illuminate/Queue/Worker.php | 17 +++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 src/Illuminate/Queue/TimeoutExceededException.php diff --git a/src/Illuminate/Queue/TimeoutExceededException.php b/src/Illuminate/Queue/TimeoutExceededException.php new file mode 100644 index 000000000000..37309ceaf04b --- /dev/null +++ b/src/Illuminate/Queue/TimeoutExceededException.php @@ -0,0 +1,8 @@ +markJobAsFailedIfWillExceedMaxAttempts( - $job->getConnectionName(), $job, (int) $options->maxTries, $e = $this->maxAttemptsExceededException($job) + $job->getConnectionName(), $job, (int) $options->maxTries, $e = $this->timoutExceededException($job) ); $this->markJobAsFailedIfWillExceedMaxExceptions( @@ -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.' ); }