⚡️ Supercharged job chains for Laravel
Notice 14/05/2024
I am no longer going to be accepting new features for Laravel Haystack. I intend to still ensure security fixes
are made, but I feel that the project is now complete. Additionally, I feel that Laravel’s job batches and
chains in Laravel 10+ are a lot more powerful and you may not need Laravel Haystack in 2024.
Laravel Haystack provides supercharged job chains for Laravel. It comes with powerful features like delaying jobs for as long as you like, applying middleware to every job, sharing data and models between jobs and even chunking jobs. Laravel Haystack supports every queue connection/worker out of the box. (Database, Redis/Horizon, SQS). It’s great if you need to queue thousands of jobs in a chain or if you are looking for features that the original Bus chain doesn’t provide.
$haystack = Haystack::build()
->addJob(new RecordPodcast)
->addJob(new ProcessPodcast)
->addJob(new PublishPodcast)
->then(function () {
// Haystack completed
})
->catch(function () {
// Haystack failed
})
->finally(function () {
// Always run either on success or fail.
})
->withMiddleware([
// Middleware for every job
])
->withDelay(60)
->withModel($user)
->dispatch();
That’s right! Laravel does have job chains but they have some disadvantages that you might want to think about.
then
, catch
, finally
callable methods that batched jobs do.Laravel Haystack aims to solve this by storing the job chain in the database and queuing one job at a time. When the job is completed, Laravel Haystack listens out for the “job completed” event and queues the next job in the chain from the database.
then
, catch
and finally
.You can install the package with Composer. Laravel Haystack Requires Laravel 8+ and PHP 8.1
composer require sammyjo20/laravel-haystack
Next, just run the installation command!
php artisan haystack:install
Click here to read the documentation
While I never expect anything, if you would like to support my work, you can donate to my Ko-Fi page by simply buying me a coffee or two!
Thank you for using Laravel Haystack ❤️