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 for chains to be added to batches via PendingChain #34707

Closed
wants to merge 9 commits into from
Closed

[8.x] Allow for chains to be added to batches via PendingChain #34707

wants to merge 9 commits into from

Conversation

Orrison
Copy link
Contributor

@Orrison Orrison commented Oct 6, 2020

This is an alternative to #34612 that uses the actual Bus::chain method rather than a nested array syntax.

It could be used as so:

$batch = Bus::batch([
            new Test1Job(),
            Bus::chain([
                new Test2Job(),
                new Test3Job(),
                function() {
                    // closure
                },
            ]),
        ])->then(function (Batch $batch) {
            Log::info('Test Complete!');
        })->name('Test')->dispatch();

Each job, even each one in the chain including the closure, is given a batchId just as they normally would and the then only fires once all are completed.

Batching adds an amazing functionality of doing something once a bunch of things are completed. But it could be very helpful to include a chain within the "bunch of things" since sometimes certain things have to happen before the other. But it would be really beneficial if that all could be tracked and something is done once they all are completed within the batch.

Signed-off-by: Kevin Ullyott <ullyott.kevin@gmail.com>
Signed-off-by: Kevin Ullyott <ullyott.kevin@gmail.com>
Signed-off-by: Kevin Ullyott <ullyott.kevin@gmail.com>
Signed-off-by: Kevin Ullyott <ullyott.kevin@gmail.com>
Signed-off-by: Kevin Ullyott <ullyott.kevin@gmail.com>
Signed-off-by: Kevin Ullyott <ullyott.kevin@gmail.com>
Signed-off-by: Kevin Ullyott <ullyott.kevin@gmail.com>
Signed-off-by: Kevin Ullyott <ullyott.kevin@gmail.com>
Signed-off-by: Kevin Ullyott <ullyott.kevin@gmail.com>
@taylorotwell
Copy link
Member

So... which PR do you prefer? Is this better? If so, how?

@Orrison
Copy link
Contributor Author

Orrison commented Oct 6, 2020

So... which PR do you prefer? Is this better? If so, how?

I think I prefer this one as it seems a little more like a "native Laravel way".

The other PR does introduce a nested array syntax that may be a little confusing while this makes it very clear that you are including a chain within the batch.

@taylorotwell
Copy link
Member

Problem with this PR is you're using a Illuminate\Foundation class within an outside component.

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.

None yet

2 participants