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] Pass listener arguments to middleware method #41209

Merged
merged 1 commit into from
Feb 24, 2022

Conversation

adriaanzon
Copy link
Contributor

In #38128, support for job middleware was added to queued event listensers.

This pull request passes the same arguments that are passed to handle(), to the middleware() method. Doing so allows us to construct the middleware with certain context. In my use case, I am using implementing a rate limiter that is scoped to a specific user:

class SyncToExternalService implements ShouldQueue
{
    public function handle(Updated $event)
    {
    }

    public function middleware(Updated $event)
    {
        return [new RateLimitMiddleware($event->user->external_service_id)];
    }
}

This is backwards compatible because the argument list on middleware() can still remain empty.

@adriaanzon
Copy link
Contributor Author

I suppose the same can be done for the listener's backoff() and retryUntil() methods.

@taylorotwell taylorotwell merged commit bab6eb3 into laravel:9.x Feb 24, 2022
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.

None yet

2 participants