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

[9.x] Add skip cancelled middleware #45869

Merged
merged 3 commits into from
Jan 30, 2023
Merged

[9.x] Add skip cancelled middleware #45869

merged 3 commits into from
Jan 30, 2023

Conversation

morrislaptop
Copy link
Contributor

This PR adds a small Job middleware which will skip Batchable jobs if the associated batch is cancelled.

This basically removes the need for an initial if statement from the handle method:

/**
 * Execute the job.
 *
 * @return void
 */
public function handle()
{
    if ($this->batch()->cancelled()) {
        return;
    }
 
    // Continue processing...
}

To this:

public function middleware()
{
    return [new SkipCancelled];
}

Which aligns with the purpose of middleware from the docs

Job middleware allow you to wrap custom logic around the execution of queued jobs, reducing boilerplate in the jobs themselves.

@taylorotwell taylorotwell merged commit f864b92 into laravel:9.x Jan 30, 2023
@driesvints
Copy link
Member

Thanks! @morrislaptop can you also send a PR to the docs?

@morrislaptop
Copy link
Contributor Author

@driesvints laravel/docs#8495

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants