Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.4] Fix job release when job exceptions occur #18737

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Illuminate/Queue/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,9 @@ protected function handleJobException($connectionName, $job, WorkerOptions $opti
// If we catch an exception, we will attempt to release the job back onto the queue
// so it is not lost entirely. This'll let the job be retried at a later time by
// another listener (or this same one). We will re-throw this exception after.
if (! $job->isDeleted()) {
// Do not release the job back onto the queue if the job is either deleted, failed
// or if the job has already been released from the JobExceptionOccurred event listener.
if (! ($job->isReleased() || $job->isDeleted() || $job->hasFailed())) {
$job->release($options->delay);
}
}
Expand Down
18 changes: 17 additions & 1 deletion tests/Queue/QueueWorkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,11 @@ class WorkerFakeJob
public $callback;
public $deleted = false;
public $releaseAfter;
public $released = false;
public $maxTries;
public $attempts = 0;
public $failedWith;
public $failed = false;
public $connectionName;

public function __construct($callback = null)
Expand Down Expand Up @@ -296,24 +298,38 @@ public function isDeleted()

public function release($delay)
{
$this->released = true;

$this->releaseAfter = $delay;
}

public function isReleased()
{
return $this->released;
}

public function attempts()
{
return $this->attempts;
}

public function markAsFailed()
{
//
$this->failed = true;
}

public function failed($e)
{
$this->markAsFailed();

$this->failedWith = $e;
}

public function hasFailed()
{
return $this->failed;
}

public function setConnectionName($name)
{
$this->connectionName = $name;
Expand Down