-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[8.x] Allow including a closure in a queued batch #34333
Conversation
Is this inspired by that Twitter thread? If so, would this solve that use case since if the function starts a chain that function itself would complete even while the chain is still running? So the batch might look completed before it actually is? |
@taylorotwell yes it’s inspired by the Twitter thread. I think that’s what the OP meant. To start the chain as part of the batch. |
I've played around with this for a bit as well and stumbled across the issue that Taylor mentioned. I'm pretty sure that doing it like this would incorrectly calculate the number of jobs in the batch. Bus::batch([
new Job1(),
function () {
Bus::chain([
new Job2(),
new Job3(),
]);
}
]); This would incorrectly be calculated as having 2 jobs, |
The bigger issue is that the jobs inside the chain wouldn't be aware of the batch (which might not be an issue but it feels off that they are treated differently). I'll try and polish up my proof of concept later. |
I opened up a discussion about it where I also try and explain my use case for this: #34332 |
@ksassnowski The batch won't know about the jobs in the chain yes. This PR just allows you to dispatch a closure based job inside a batch. Inside that job, you may dispatch a chain if you want, that's one of the use cases. |
Yeah, I think this PR is fine but doesn't really solve @ksassnowski's problem which I don't think is possible given the current code in the framework. The only way to make it happen is to create a batched job which dispatches the chain onto the sync queue so that all the chain jobs run sequentially and synchronously within that batch job's process. Does that solution work for you @ksassnowski? |
Can you have a look my draft PR to see if this is something worth including in the framework? #34337 |
This PR allows including a closure in a queued batch: