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

[10.x] Allow Listeners to dynamically specify delay using withDelay #48026

Merged
merged 1 commit into from
Aug 11, 2023

Conversation

calebdw
Copy link
Contributor

@calebdw calebdw commented Aug 10, 2023

Hello!

There's currently not a way to specify the queued listener delay at runtime like there is with the queue and connection (viaQueue and viaConnection, respectively). This PR allows a listener to define a withDelay method (NotificationSender uses same method name) that can accept the event to adjust the delay based on the event properties.

Example
class Listener implements ShouldQueue
{
    public function __invoke(Event $event): void
    {
        // ...
    }

    public function withDelay(Event $event): int
    {
        return $event->fooBar
            ? <short_delay>
            : <long_delay>;
    }
}

If this PR is accepted then I'll submit a PR to the docs repo.

Thanks!

@taylorotwell taylorotwell merged commit 5a7f2b4 into laravel:10.x Aug 11, 2023
21 checks passed
@calebdw
Copy link
Contributor Author

calebdw commented Aug 11, 2023

Thank you sir!

@calebdw calebdw deleted the delay_listeners branch June 13, 2024 04:05
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