freekmurze / freek-dev-comments

2 stars 0 forks source link

1734-how-to-group-queued-jobs-using-laravel-8s-new-batch-class #41

Open utterances-bot opened 4 years ago

utterances-bot commented 4 years ago

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

ejunker commented 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.

Dotunj commented 4 years ago

Awesome post Freek. I also loved the practical examples you used to illustrate the concept.

freekmurze commented 4 years ago

Thanks @Dotunj

kurucu commented 4 years ago

Hi Freek, great post! Are these updates going to allow Mailcoach to be hosted on Vapor?

iaK commented 3 years ago

Thanks a lot for this post! Do you have any tips on how to test this? Especially the final method?

designvoid commented 3 years ago

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?

teejakeksit commented 3 years ago

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.