Skip to content

[12.x] Set job instance on "failed" command instance #55617

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

Merged

Conversation

willrowe
Copy link
Contributor

This sets the job instance on the command instance created when attempting to call the failed method on a job class. It is fully backwards compatible.

I have a job that does some logging to a channel that is only for the job itself. In order to group the messages together, I include the job instance ID in the log context. If something goes wrong, I wanted to log an error by adding a failed method to the job class. However, I could not reference the job instance from within the failed method even though I was using the InteractsWithQueue trait.

@willrowe willrowe force-pushed the feature/job-instance-in-failed-method branch from 6fffe41 to 85ba225 Compare May 1, 2025 00:00
@taylorotwell taylorotwell merged commit b0cb237 into laravel:12.x May 1, 2025
58 checks passed
@taylorotwell
Copy link
Member

Thanks!

@willrowe willrowe deleted the feature/job-instance-in-failed-method branch May 1, 2025 22:01
@AhmedAlaa4611
Copy link
Contributor

I notice that we have the setJobInstanceIfNecessary method with the same structure and body in two different places Illuminate\Queue\CallQueuedHandler and Illuminate\Events\CallQueuedListener.
Should we make it in a separate trait?

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.

3 participants