Add Release queue middleware#60630
Conversation
Adds a `Release` queue middleware that releases a job back onto the queue
based on a condition, instead of executing it immediately. Where `Skip`
deletes the job, `Release` defers its execution to a later attempt.
Example usage:
```php
use Illuminate\Queue\Middleware\Release;
public function middleware(): array
{
return [
Release::when(
fn () => ! $this->order->isPaid(),
retryAfter: 60
),
];
}
```
`Release::when($condition)` releases the job when the condition is truthy.
`Release::unless($condition)` releases the job when the condition is not
truthy. `$retryAfter` defines the delay, in seconds, before the job is
executed again.
|
Here is a real-world use case from a music distribution system I'm working on. When an initial delivery is performed, it can remain in progress for several hours while waiting for confirmation from the platforms. During this period, the user can trigger a takedown; the takedown must not run while the delivery is still in progress. The reverse is also true: a delivery for the same release must not start while a takedown is in progress. use Illuminate\Queue\Middleware\Release;
public function middleware(): array
{
return [
Release::when(
fn () => $this->release->hasPendingInitialDelivery(),
releaseAfter: 300
),
];
}In this case, the middleware simply defers the job until the opposing operation has finished. This doesn't really match the role of |
Adds a
Releasequeue middleware that releases a job back onto the queue based on a condition, instead of executing it immediately.Where
Skipdeletes the job,Releasedefers its execution to a later attempt.Example usage:
Release::when($condition)releases the job when the condition is truthy.Release::unless($condition)releases the job when the condition is not truthy.$releaseAfterdefines the delay, in seconds, before the job is executed again.