From d50424ffdb19c7f221e58eaa53fef2105403d89c Mon Sep 17 00:00:00 2001 From: Milwad <98118400+milwad-dev@users.noreply.github.com> Date: Wed, 14 May 2025 18:58:11 +0330 Subject: [PATCH 1/3] Update queues.md --- queues.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/queues.md b/queues.md index 73cf74504cd..e63ffddd155 100644 --- a/queues.md +++ b/queues.md @@ -738,6 +738,15 @@ public function middleware(): array } ``` +If you would like to delete a job by condition, you can use the `deleteWhen` method: + +```php +public function middleware(): array +{ + return [(new ThrottlesExceptions(2, 10 * 60))->deleteWhen(Exception::class)]; +} +``` + 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`: ```php From 07e98f2add43226055ebeebb3b1f8f1fef60f231 Mon Sep 17 00:00:00 2001 From: Milwad Khosravi <98118400+milwad-dev@users.noreply.github.com> Date: Wed, 14 May 2025 20:00:40 +0330 Subject: [PATCH 2/3] Update queues.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sebastian Hädrich <11225821+shaedrich@users.noreply.github.com> --- queues.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/queues.md b/queues.md index e63ffddd155..9c214afe86f 100644 --- a/queues.md +++ b/queues.md @@ -738,7 +738,7 @@ public function middleware(): array } ``` -If you would like to delete a job by condition, you can use the `deleteWhen` method: +Contrary to using `->when(…)`, which indicates that the job should not be released back and instead throw an exception, `->deleteWhen(…)` allows you to exit the circuit of either throw exception or release back onto the queue, and instead to just delete the job. In this way, the job will just be deleted when this exception occurs. (Of course, you can still choose to report the exception just like before.): ```php public function middleware(): array From 9f50ec55328b0ff7d36f4950d0acda19b63ee556 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 15 May 2025 16:26:15 -0500 Subject: [PATCH 3/3] Update queues.md --- queues.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/queues.md b/queues.md index 9c214afe86f..fb83dd5ee4a 100644 --- a/queues.md +++ b/queues.md @@ -738,12 +738,20 @@ public function middleware(): array } ``` -Contrary to using `->when(…)`, which indicates that the job should not be released back and instead throw an exception, `->deleteWhen(…)` allows you to exit the circuit of either throw exception or release back onto the queue, and instead to just delete the job. In this way, the job will just be deleted when this exception occurs. (Of course, you can still choose to report the exception just like before.): +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: ```php +use App\Exceptions\CustomerDeletedException; +use Illuminate\Queue\Middleware\ThrottlesExceptions; + +/** + * Get the middleware the job should pass through. + * + * @return array + */ public function middleware(): array { - return [(new ThrottlesExceptions(2, 10 * 60))->deleteWhen(Exception::class)]; + return [(new ThrottlesExceptions(2, 10 * 60))->deleteWhen(CustomerDeletedException::class)]; } ```