-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[8.x] Fix scheduler unique job #39197
Conversation
@paras-malhotra do you have any thoughts on this? |
I dont believe unique jobs were ever meant for task scheduling. @ericsssan what is your use case here and can it not be solved using |
Hi Use case: Objective: What works:
What does not work:
https://laravel.com/docs/8.x/scheduling#scheduling-queued-jobs According to the doc , job method in Task Scheduling is a convenient method for call. But dispatching a unique job from scheduler within call method callback works as expected whereas dispatching with job method does not. If you believe that sheduler is not meant to dispatch unique job then I think we can just put it in the doc to warn others about it. I just think that dispatching a job should work as expected regardless of where you dispatch it. But the problem is we get a different dispatcher when we dispatch with schedule->job() and that makes it inconsistent. Cheers |
Do you have a good understanding of why your change fixes it? If so, can you explain? |
Yes. When dispatching a job elsewhere it goes through ShouldDispatch method in PendingDispatch class.
But when using $schedule->job(), it does not go through PendingDispatch class.
Here is the job method call dispatchToQueue method.
Then goes on to call getDispatcher method and chain call dispatch method.
And here, getDispatcher simply just resolve Dispatcher from a container and dispatch without going through PendingDispatch class. I can think of 2 ways to fix this:
- $this->getDispatcher()->dispatch(
- $job->onConnection($connection)->onQueue($queue)
- );
+ dispatch($job)->onConnection($connection)->onQueue($queue);
Please let me know if I missed out something. Cheers |
Replacing with #39302 because using Foundation classes from the console component isn't really allowed. Had to refactor some things into the Bus component. |
Hi maintainers
I discovered a bug where scheduling job that implemented ShouldBeUnique failed to enforce uniqueness.
I have included test case and possible fix.
Please review.
Thanks