Skip to content

Instantly share code, notes, and snippets.

@crystaldaking
Created October 26, 2020 12:47
Show Gist options
  • Save crystaldaking/561cb33824f76c1f9e429ae17a835d3c to your computer and use it in GitHub Desktop.
Save crystaldaking/561cb33824f76c1f9e429ae17a835d3c to your computer and use it in GitHub Desktop.
batch
use App\Jobs\ProcessPodcast;
use App\Podcast;
use Illuminate\Bus\Batch;
use Illuminate\Support\Facades\Bus;
use Throwable;
$batch = Bus::batch([
new ProcessPodcast(Podcast::find(1)),
new ProcessPodcast(Podcast::find(2)),
new ProcessPodcast(Podcast::find(3)),
new ProcessPodcast(Podcast::find(4)),
new ProcessPodcast(Podcast::find(5)),
])->then(function (Batch $batch) {
// All jobs completed successfully...
})->catch(function (Batch $batch, Throwable $e) {
// First batch job failure detected...
})->finally(function (Batch $batch) {
// The batch has finished executing...
})->dispatch();
return $batch->id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment