From 0174b7dadb496d79c40e8b10daa86399f2c30aec Mon Sep 17 00:00:00 2001 From: Jack Bayliss Date: Fri, 17 Jul 2026 12:28:11 +0100 Subject: [PATCH] add the exception to JobReleasedAfterException --- src/Illuminate/Queue/Events/JobReleasedAfterException.php | 4 +++- src/Illuminate/Queue/Worker.php | 2 +- tests/Queue/QueueWorkerTest.php | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Queue/Events/JobReleasedAfterException.php b/src/Illuminate/Queue/Events/JobReleasedAfterException.php index 3ee709898fdd..9799d7c9ccd6 100644 --- a/src/Illuminate/Queue/Events/JobReleasedAfterException.php +++ b/src/Illuminate/Queue/Events/JobReleasedAfterException.php @@ -10,11 +10,13 @@ class JobReleasedAfterException * @param string $connectionName The connection name. * @param \Illuminate\Contracts\Queue\Job $job The job instance. * @param int|null $backoff The backoff delay. + * @param \Throwable|null $exception The exception that caused the job to be released. */ public function __construct( public $connectionName, public $job, - public $backoff = null + public $backoff = null, + public $exception = null, ) { } } diff --git a/src/Illuminate/Queue/Worker.php b/src/Illuminate/Queue/Worker.php index 12c24e9e1813..a4d0b78a3ecc 100644 --- a/src/Illuminate/Queue/Worker.php +++ b/src/Illuminate/Queue/Worker.php @@ -614,7 +614,7 @@ protected function handleJobException($connectionName, $job, WorkerOptions $opti $job->release($backoff); $this->events->dispatch(new JobReleasedAfterException( - $connectionName, $job, $backoff + $connectionName, $job, $backoff, $e )); } } diff --git a/tests/Queue/QueueWorkerTest.php b/tests/Queue/QueueWorkerTest.php index 8e481a993a1a..6e50b39cfb8c 100755 --- a/tests/Queue/QueueWorkerTest.php +++ b/tests/Queue/QueueWorkerTest.php @@ -624,11 +624,12 @@ public function testJobReleasedEvent() $worker = $this->getWorker('default', ['queue' => [$job]]); $worker->runNextJob('default', 'queue', $this->workerOptions(['backoff' => 10])); - $this->events->shouldHaveReceived('dispatch')->with(m::on(function ($event) use ($job) { + $this->events->shouldHaveReceived('dispatch')->with(m::on(function ($event) use ($job, $e) { return $event instanceof JobReleasedAfterException && $event->connectionName === 'default' && $event->job === $job - && $event->backoff === 10; + && $event->backoff === 10 + && $event->exception === $e; }))->once(); }