Skip to content

Commit 87d26fb

Browse files
milwad-devshaedrichtaylorotwell
authored
[12.x] Add deleteWhen method in job middleware (#10400)
* Update queues.md * Update queues.md Co-authored-by: Sebastian Hädrich <[email protected]> * Update queues.md --------- Co-authored-by: Sebastian Hädrich <[email protected]> Co-authored-by: Taylor Otwell <[email protected]>
1 parent 81412ad commit 87d26fb

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

queues.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,23 @@ public function middleware(): array
738738
}
739739
```
740740

741+
Unlike the `when` method, which releases the job back onto the queue or throws an exception, the `deleteWhen` method allows you to delete the job entirely when a given exception occurs:
742+
743+
```php
744+
use App\Exceptions\CustomerDeletedException;
745+
use Illuminate\Queue\Middleware\ThrottlesExceptions;
746+
747+
/**
748+
* Get the middleware the job should pass through.
749+
*
750+
* @return array<int, object>
751+
*/
752+
public function middleware(): array
753+
{
754+
return [(new ThrottlesExceptions(2, 10 * 60))->deleteWhen(CustomerDeletedException::class)];
755+
}
756+
```
757+
741758
If you would like to have the throttled exceptions reported to your application's exception handler, you can do so by invoking the `report` method when attaching the middleware to your job. Optionally, you may provide a closure to the `report` method and the exception will only be reported if the given closure returns `true`:
742759

743760
```php

0 commit comments

Comments
 (0)