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 #29152

Closed
wants to merge 2 commits into from
Closed

[5.8] Prevent a job from firing if it's been marked as deleted #29152

wants to merge 2 commits into from

Conversation

gms8994
Copy link
Contributor

@gms8994 gms8994 commented Jul 12, 2019

During queue job processing an Events\JobProcessing event is fired, which makes it possible to $job->delete(), however, $job->fire() still happens even on the deleted job.

This adds a check to the processing of the job to prevent that, and fires an Events\JobDeleted event that can be listened for.

Also adds output to the WorkCommand to allow seeing that a job was deleted before processing completed.

Tests included.

gms8994 added 2 commits July 12, 2019 13:24
During queue job processing an `Events\JobProcessing` event is fired, which
makes it possible to `$job->delete()`, however, `$job->fire()` still happens
even on the deleted job,.

This adds a check to the processing of the job to prevent that, and fires an
`Events\JobDeleted` event that can be listened for.

Also adds output to the `WorkCommand` to allow seeing that a job was deleted
before processing completed.

Tests included.
@GrahamCampbell GrahamCampbell changed the title Prevent a job from firing if it's been marked as deleted [5.8] Prevent a job from firing if it's been marked as deleted Jul 12, 2019
@taylorotwell
Copy link
Member

Interesting. What was your use case for deleting jobs in the Processing event?

@gms8994
Copy link
Contributor Author

gms8994 commented Jul 12, 2019

@taylorotwell I was trying to find a way to prevent "duplicated" jobs (same Job::class on the same connection with the same parameters) from running. For example, due to some legacy code, we have something that will fire Job::class, that through some unfortunate series of events can also fire Job::class later. There isn't a great way of solving that problem in our environment short of something like this.

I did look to see if there was a way to throw a specific exception that would remove the job without failing it, but couldn't find anything, and then came across deleting the job, but noticed the missing piece.

I appreciate you taking the time to look over the PR!

@gms8994
Copy link
Contributor Author

gms8994 commented Jul 12, 2019

Specifically, see https://github.com/expanse/laravel-distinct-jobs for the anticipated use of this functionality.

@taylorotwell
Copy link
Member

Do you actually need the event or can we get rid of that part?

@gms8994
Copy link
Contributor Author

gms8994 commented Jul 13, 2019

I think at least one of JobDeleted or JobProcessed should be fired, if not for my pending package then for the output of the queue:work console command to not "feel" like errors are occurring. I think JobProcessed would suffice for my needs, and would work if the code were updated to fire it - I was simply trying to stick to semantics, since the job technically wasn't processed.

@taylorotwell
Copy link
Member

Please remove the deleted event and re-submit. From what I can tell it doesn't fire if I just let a job process, even though that does delete the job after processing. I find it confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants