$haystack = Haystack::build()
->withName('Podcast Chain')
->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.
})
->paused(function () {
// Run if the haystack is paused
})
->withMiddleware([
// Middleware to apply on every job
])
->withDelay(60) // Add a delay to every job
->dispatch();
- Low memory consumption as one job is processed at a time and the chain is stored in the database
- You can delay/release jobs for as long as you want since it will use the scheduler to restart a chain. Even if your queue driver is SQS!
- It provides callback methods like
then
, catch
and finally
- Global middleware that can be applied to every single job in the chain
- Delay that can be added to every job in the chain
- You can store and retrieve data/state that is accessible to every job in the chain.
- You can store the model for later processing.