-
Notifications
You must be signed in to change notification settings - Fork 11.5k
[12.x] Add defer method to PendingDispatch #56798
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
base: 12.x
Are you sure you want to change the base?
Conversation
Thanks for submitting a PR! Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface. Pull requests that are abandoned in draft may be closed due to inactivity. |
43f358a
to
37f036b
Compare
My main concern with this is that it is different to the dispatch(MyJob::class)->afterResponse(); indicates that the job should be executed synchronously during the HTTP request, not on the queue, but after the response has been sent. e.g., it is the same as: App::terminating(fn () => MyJob::dispatchSync()); // execute the job synchronously after response has been sent
App::terminating(fn () => MyJob::dispatch()); // dispatch to queue after response sent Adding I wonder if composition is the best way forward here. It makes it unambiguous as to what is happening. // Dispatch to the queue after the execution has completed.
defer(fn () => MyJob::dispatch());
// Execute the job synchronously the execution has completed.
defer(fn () => MyJob::dispatchSync()); |
Hi Tim, Yes, when I polled people in our engineering team most people did think Happy to keep this as an internal helper for our team, but I was hoping that this would bring attention to this unclear functionality to more people and perhaps save people investigating their flame charts. Misusing |
As for the tests, they have proven to be a bit tricky. Not sure if I'm doing something wrong, but intuitively it feels like they "should" work in their current state, but they don't. |
This PR adds support for dispatching a job like:
Which wouldn't put the job on the queue until after the request, command or job is finished.
Under the hood, Laravel's
defer()
function is used. We've had adispatch_defer
method in our codebase for a while now, and I think other people could benefit from this.I've also written some tests for the dispatch logic.