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.8] Prevent a job from firing if it's been marked as deleted #29204

Merged
merged 1 commit into from
Jul 18, 2019
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
6 changes: 6 additions & 0 deletions src/Illuminate/Queue/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,12 @@ public function process($connectionName, $job, WorkerOptions $options)
$connectionName, $job, (int) $options->maxTries
);

if ($job->isDeleted()) {
$this->raiseAfterJobEvent($connectionName, $job);

return;
}

// Here we will fire off the job and let it process. We will catch any exceptions so
// they can be reported to the developers logs, etc. Once the job is finished the
// proper events will be fired to let any listeners know this job has finished.
Expand Down
16 changes: 16 additions & 0 deletions tests/Queue/QueueWorkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,22 @@ public function test_job_based_failed_delay()
$this->assertEquals(10, $job->releaseAfter);
}

public function test_job_does_not_fire_if_deleted()
{
$job = new WorkerFakeJob(function () {
return true;
});

$worker = $this->getWorker('default', ['queue' => [$job]]);
$job->delete();
$worker->runNextJob('default', 'queue', $this->workerOptions());

$this->events->shouldHaveReceived('dispatch')->with(m::type(JobProcessed::class))->once();
$this->assertFalse($job->hasFailed());
$this->assertFalse($job->isReleased());
$this->assertTrue($job->isDeleted());
}

/**
* Helpers...
*/
Expand Down