-
Notifications
You must be signed in to change notification settings - Fork 10.9k
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
[5.7] When scheduling a job, respect the already set queue #25159
Conversation
When scheduling a job, we need to respect the already set queue in the job itself. This commit will prevent the queue from getting overwritten.
Could you add a test for this? |
Still need to dispatch the queued job, but because it's a queued job, it seems harder to fire it.
Hi @sisve, I tried to, but I am struggling to fire a scheduled job in my unit test. |
@petervmeijgaard I didn't try this, but off the top of my head... $events = $scheduler->events();
foreach ($events as $event) {
$event->run($container);
} |
The code doesn't even look correct anymore? Your original PR code looked correct. I don't know why you are setting $queue to a booelan now? |
…ue is null. If so, use the queue specified on the job. Otherwise use the queue variable.
Oh my apologies, I was tinkering around with trying different approaches by setting the queue different ways. What I intended to do was Coming from a JavaScript perspective, I thought that the code above would result in |
@@ -97,6 +97,8 @@ public function job($job, $queue = null, $connection = null) | |||
$job = is_string($job) ? resolve($job) : $job; | |||
|
|||
if ($job instanceof ShouldQueue) { | |||
$queue = $queue !== null ? $queue : $job->queue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$queue = $queue ?? $job->queue;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is an empty string a valid queue name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never mind, I had a brain-fart. I was thinking of the ?:
operator. ??
seem to work as expected.
Tests fail. Please re-submit with working tests. |
Problem description
When creating a job, we sometimes want to define in which queue the job should run.
Sometimes that's something that we want to define in the job itself.
When creating a job, we often specify which queue it should be stored at in the constructor:
But when scheduling this job, we need to specify a queue in which the job should run.
This results in having to specify the queue multiple times instead of just once.
Proposed solution
It would be a good solution to respect the already defined queue on the custom job class.
Using the example above, it'll result in a solution something like this: