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

[7.x] Allow setting the event handler queue via a getQueue() method #32770

Merged
merged 3 commits into from
Jun 8, 2020

Conversation

lupinitylabs
Copy link
Contributor

Using queued event listeners, it is possible to set the queue the resulting job should be executed on using the $queue attribute. This attribute is then adopted by the dispatcher.

However, it is not possible to set the queue name from the config, the environment or otherwise programatically, because the listener instance is created without invoking the constructor in Dispatcher::createListenerAndJob(). Thus, trying to set the queue name in the constructor or anywhere else in the Listener has no effect.

This pull request proposes a non-breaking change to the Dispatcher class that allows a user to set the queue name by defining a getQueue() method within the Listener, as it is already done with retryAfter and retryUntil methods.

If no getQueue method is defined, the code falls back to use the $queue attribute or null, as it was before.

The benefit of this change is to provide developers with a flexible way to influence the target queues instead of having to hard code them.

@GrahamCampbell GrahamCampbell changed the title [7.x] allow setting the event handler queue via a getQueue() method. [7.x] Allow setting the event handler queue via a getQueue() method May 12, 2020
@taylorotwell
Copy link
Member

public function __construct()
{
    $this->queue = 'whatever-you-want';
}

@lupinitylabs
Copy link
Contributor Author

lupinitylabs commented May 13, 2020

public function __construct()
{
    $this->queue = 'whatever-you-want';
}

Sure, as I described above, that was my first attempt, but it doesn't work because the listener is instantiated using $listener = (new ReflectionClass($class))->newInstanceWithoutConstructor(); hence the pull request.

Please check out a quick project I hacked together at https://github.com/lupinitylabs/queuename in the hopes of making myself clearer.

Please note: the same issue exists with setting the tries property, so the pull request should probably even be extended by a method to set tries, too.

@lupinitylabs
Copy link
Contributor Author

@taylorotwell Any chance to have this re-opened?

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