8000 Add delete when for throttle exceptions job middleware by moshe-autoleadstar · Pull Request #55717 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

Add delete when for throttle exceptions job middleware #55717

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

Conversation

moshe-autoleadstar
Copy link
Contributor
@moshe-autoleadstar moshe-autoleadstar commented May 12, 2025

What

Adds ->deleteWhen(..) to ThrottlesExceptions job middleware (and of course ThrottlesExceptionsWithRedis)

Examples

use Illuminate\Queue\Middleware\ThrottlesExceptions;
 
public function middleware(): array
{
    return [
        new ThrottlesExceptions(10, 5)
            ->deleteWhen(ExceptionThatIsOk::class),
    ];
}
use Illuminate\Queue\Middleware\ThrottlesExceptions;
 
public function middleware(): array
{
    return [
        new ThrottlesExceptions(10, 5)
            ->deleteWhen(fn (\Throwable $throwable) => str($throwable)->contains('its all ok'))
            ->deleteWhen(fn (\Throwable $throwable) => $throwable instanceof \Illuminate\Database\QueryException
                && str($throwable->getMessage())->contains('a foreign key constraint fails')
            ),
    ];
}

Details

When using ThrottlesExceptions job middleware, we can pass a callback for ->when(..) the job should not be released back and instead throw an exception. But for most use cases, you will likely be retrying this job and therefore the job will be attempted again. The new ->deleteWhen(..) functionality 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.)

@moshe-autoleadstar
Copy link
Contributor Author

i see that i have here commits from another branch. im reopening with clean working repository. see #55718

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.

1 participant
0