Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip if batch cancelled #8495

Merged
merged 4 commits into from
Jan 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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