-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
dispatch method does not respect ShouldBeUnique on jobs #45781
Comments
This is intentional I feel. The former methods you used are all actions on the jobs themselves while the Dispatcher just works differently. If you want to use the ShouldBeUnique you already have two ways of making that work. |
This must be documented. Why can't we make them work the same way?? |
Feel free to send in a pr 👍 |
I meant to say: send in a PR to the docs. We can't change the behavior here. |
Just a note for someone who experienced the same issue (to save your time):
\Illuminate\Bus\Dispatcher::dispatch($jobInstance) while /**
* Handle the object's destruction.
*
* @return void
*/
public function __destruct()
{
if (! $this->shouldDispatch()) {
return;
} elseif ($this->afterResponse) {
app(Dispatcher::class)->dispatchAfterResponse($this->job);
} else {
app(Dispatcher::class)->dispatch($this->job);
}
} and inside /**
* Determine if the job should be dispatched.
*
* @return bool
*/
protected function shouldDispatch()
{
if (! $this->job instanceof ShouldBeUnique) {
return true;
}
return (new UniqueLock(Container::getInstance()->make(Cache::class)))
->acquire($this->job);
} So, |
Description:
Steps To Reproduce:
Create a test job:
Then create a Controller and dispatch the job via
dispatch()
helper available in all ControllersStart the worker
Now hit the controller via a route twice, notice worker will process 2 jobs.
The problem lies here in this trait
framework/src/Illuminate/Foundation/Bus/DispatchesJobs.php
Line 17 in 247735e
This method is dispatching the jobs in a different way which does not respect the
ShouldBeUnique
contractThe text was updated successfully, but these errors were encountered: