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

[8.x] Allow including a closure in a queued batch #34333

Merged
merged 3 commits into from
Sep 15, 2020

Conversation

themsaid
Copy link
Member

This PR allows including a closure in a queued batch:

Bus::batch([
    new ProcessPodcast,
    function(){
        // ...
    },
    new ReleasePodcast
])->dispatch();

@taylorotwell
Copy link
Member

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?

@themsaid
Copy link
Member Author

@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.

@ksassnowski
Copy link
Contributor

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, Job1 and the closure, when in fact it should be 3 jobs.

@ksassnowski
Copy link
Contributor

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.

@ksassnowski
Copy link
Contributor

I opened up a discussion about it where I also try and explain my use case for this: #34332

@themsaid
Copy link
Member Author

@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.

@taylorotwell
Copy link
Member

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?

@ksassnowski
Copy link
Contributor

Can you have a look my draft PR to see if this is something worth including in the framework? #34337

@taylorotwell taylorotwell merged commit 02d1424 into laravel:8.x Sep 15, 2020
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