Open utterances-bot opened 4 years ago
I'm not sure if it could be done, but I wish I could pass an iterable
into Batch::add()
so then you could pass in LazyCollection
and generators. The main difference though is you wouldn't have a total count so you would not know if the batch is almost done but it could keep adding jobs until the iteration stopped.
Awesome post Freek. I also loved the practical examples you used to illustrate the concept.
Thanks @Dotunj
Hi Freek, great post! Are these updates going to allow Mailcoach to be hosted on Vapor?
Thanks a lot for this post! Do you have any tips on how to test this? Especially the final method?
Hey Freek! Thanks once again for a great article! Just wondering why you went with the approach of creating the batch with an empty array and didn't use the approach of utilising a 'hydrator' job as per the laravel docs? Were there some issues you encountered?
Re. the method for taking action at the end of a batch - if jobs fail and are requeued and/or you have multiple queue workers, you might end up processing your ending job before you intend to. A work around is to check the batch_id for outstanding jobs and requeue your final job with a delay if you're not ready. Alternatively you can have a scheduled task to monitor your batches and take action when they have no outstanding tasks left.
How to group queued jobs using Laravel 8's new Batch class - Freek Van der Herten's blog on PHP, Laravel and JavaScript
Freek Van der Herten is a developer and partner at Spatie.
https://freek.dev/1734-how-to-group-queued-jobs-using-laravel-8s-new-batch-class