Source: divinglaravel.com

Job Batching in Laravel: How It Works

Category: Laravel, Laravel

Laravel 8 ships with a neat feature that allows us to dispatch a group of jobs to the queue to be executed in parallel. Here's an example from the official docs: 👋 I recently published a book titled "Laravel Queues in Action" that covers everything I know about running queues in Laravel.

Now that the batch information is stored in the database, Laravel stores the batch ID in each job instance we pass to the batch and then dispatches the jobs to the queue: This snippet is from the add() method of the Illuminate\Bus\Batch class. While dispatching the jobs to the queue, Laravel increments the jobs count in the database row where the batch is stored.

This method decrements the number of pending batch jobs in the database and calls the proper callbacks: If there aren't any pending jobs in the batch, Laravel will mark the batch as finished by updating the finished_at timestamp in the database.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners