3

Laravel 8 introduced Job Batching, which allows to execute jobs in batches and perform actions on batch completion. The feature itself seems very useful, and it even has an Illuminate\Bus\Batch instance, which allows to inspect and interact with the Jobs Batch.

There seems to be a method to fetch a single Batch by id Bus::findBatch($batchId);, but unfortunately I couldn't find a method to fetch a collection of Batches. Is it possible to fetch multiple Jobs Batches, or the only way is to separately call Bus::findBatch($batchId); for each $batchId in job_batches table?

Yerke
  • 2,187
  • 3
  • 19
  • 33

1 Answers1

1

I took a look at the implementation of laravel horizon. It seems that they are creating a service provider which than registers the commands and services used by the horizon panel. If that service provider is booted (meaning you have horizon installed) an instance of BatchRepository can be catched in any controller constructor or method. The BatchRepository-object than offers a get method for retrieving the list of batches in database.

enter image description here enter image description here Should be possible to retrieve the lists by using the horizon-api-routes also. See:

enter image description here

C4pt4inC4nn4bis
  • 586
  • 1
  • 6
  • 18