Download the PHP package timmylindh/laravel-batch-dispatcher without Composer
On this page you can find all versions of the php package timmylindh/laravel-batch-dispatcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download timmylindh/laravel-batch-dispatcher
More information about timmylindh/laravel-batch-dispatcher
Files in timmylindh/laravel-batch-dispatcher
Package laravel-batch-dispatcher
Short Description Batch Laravel queued jobs and queued event listeners into a single queued job dispatched at the end of the request.
License MIT
Homepage https://github.com/timmylindh/laravel-batch-dispatcher
Informations about the package laravel-batch-dispatcher
laravel-batch-dispatcher
Batch queued jobs and queued event listeners into a single queued job. This reduces the number of queue requests by capturing multiple dispatches and sending them as one job that processes all items.
Installation
Requires:
- Laravel >= 10
- PHP >= 8.1
You can install the package via composer:
You can publish the config file with:
Usage
Behavior
- All calls to
dispatch(),SomeJob::dispatch(), andEvent::dispatch()will be buffered during the request. - On terminate, the package queues a single wrapper job which in turn dispatches all buffered jobs and queued listeners.
Configuration
You can publish the config file with:
The batching behavior is controlled by config/batch-dispatcher.php:
Middleware
Setting enable_middleware = true will automatically apply the batching to the api and web middleware groups. You can apply the batching to specific routes or groups by adding the BatchRequests middleware.
Notes
- Only instances of jobs implementing
ShouldQueueand queued event listeners are batched. - Per-job queue options (connection/queue/delay) are respected when listeners are enqueued by the wrapper. Jobs are dispatched as usual by the wrapper.
How it works
During the request, we intercept:
- Bus dispatches of
ShouldQueuejobs and store the job instances in memory - Event dispatches with queued listeners and capture their queued calls
On terminate, a single ProcessBatch job is queued. It then dispatches the buffered jobs and enqueues/invokes listeners.
Testing
Credits
- Timmy Lindholm
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-batch-dispatcher with dependencies
illuminate/bus Version ^10.0||^11.0||^12.0
illuminate/contracts Version ^10.0||^11.0||^12.0
illuminate/events Version ^10.0||^11.0||^12.0
illuminate/http Version ^10.0||^11.0||^12.0
illuminate/queue Version ^10.0||^11.0||^12.0
illuminate/support Version ^10.0||^11.0||^12.0