Skip to content

Commit 5dc8f38

Browse files
khepintaylorotwell
andauthored
Document new ability to add batches to job chains (#9120)
* Document new ability to add batches to job chains * Section title * MD has significant whitespace * formatting * Update queues.md --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent d30672c commit 5dc8f38

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

queues.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- [Job Batching](#job-batching)
2424
- [Defining Batchable Jobs](#defining-batchable-jobs)
2525
- [Dispatching Batches](#dispatching-batches)
26+
- [Chains & Batches](#chains-and-batches)
2627
- [Adding Jobs To Batches](#adding-jobs-to-batches)
2728
- [Inspecting Batches](#inspecting-batches)
2829
- [Cancelling Batches](#cancelling-batches)
@@ -1288,8 +1289,8 @@ If you would like to specify the connection and queue that should be used for th
12881289
// All jobs completed successfully...
12891290
})->onConnection('redis')->onQueue('imports')->dispatch();
12901291

1291-
<a name="chains-within-batches"></a>
1292-
#### Chains Within Batches
1292+
<a name="chains-and-batches"></a>
1293+
### Chains & Batches
12931294

12941295
You may define a set of [chained jobs](#job-chaining) within a batch by placing the chained jobs within an array. For example, we may execute two job chains in parallel and execute a callback when both job chains have finished processing:
12951296

@@ -1311,6 +1312,27 @@ You may define a set of [chained jobs](#job-chaining) within a batch by placing
13111312
// ...
13121313
})->dispatch();
13131314

1315+
Conversely, you may run batches of jobs within a [chain](#job-chaining) by defining batches within the chain. For example, you could first run a batch of jobs to release multiple podcasts then a batch of jobs to send the release notifications:
1316+
1317+
use App\Jobs\FlushPodcastCache;
1318+
use App\Jobs\ReleasePodcast;
1319+
use App\Jobs\SendPodcastReleaseNotification;
1320+
use Illuminate\Support\Facades\Bus;
1321+
1322+
Bus::chain([
1323+
new FlushPodcastCache,
1324+
Bus::batch([
1325+
new ReleasePodcast(1),
1326+
new ReleasePodcast(2),
1327+
]),
1328+
Bus::batch([
1329+
new SendPodcastReleaseNotification(1),
1330+
new SendPodcastReleaseNotification(2),
1331+
]),
1332+
])->then(function () {
1333+
// ...
1334+
})->dispatch();
1335+
13141336
<a name="adding-jobs-to-batches"></a>
13151337
### Adding Jobs To Batches
13161338

0 commit comments

Comments
 (0)