Skip to content

Commit

Permalink
Skip if batch cancelled (#8495)
Browse files Browse the repository at this point in the history
* add docs for SkipIfBatchCancelled

* typo

* Update queues.md

* Update queues.md

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
morrislaptop and taylorotwell authored Jan 31, 2023
1 parent f84d533 commit 474adc9
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions queues.md
Original file line number Diff line number Diff line change
Expand Up @@ -1415,20 +1415,18 @@ Sometimes you may need to cancel a given batch's execution. This can be accompli
}
}

As you may have noticed in previous examples, batched jobs should typically check to see if the batch has been cancelled at the beginning of their `handle` method:
As you may have noticed in the previous examples, batched jobs should typically determine if their corresponding batch has been cancelled before continuing execution. However, for convenience, you may assign the `SkipIfBatchCancelled` [middleware](#job-middleware) to the job instead. As its name indicates, this middleware will instruct Laravel to not process the job if its corresponding batch has been cancelled:

use Illuminate\Queue\Middleware\SkipIfBatchCancelled;

/**
* Execute the job.
* Get the middleware the job should pass through.
*
* @return void
* @return array
*/
public function handle()
public function middleware()
{
if ($this->batch()->cancelled()) {
return;
}

// Continue processing...
return [new SkipIfBatchCancelled];
}

<a name="batch-failures"></a>
Expand Down

0 comments on commit 474adc9

Please sign in to comment.