Open kellerjmrtn opened 3 weeks ago
Thank you for reporting this issue!
As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.
If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.
Thank you!
Laravel Version
10.48.12 (although I believe relevant code has not changed in 11.x)
PHP Version
8.1.28
Database Driver & Version
Redis 7.2.5 (although issue should exist with other cache drivers)
Description
When dispatching jobs, the
ShouldBeUnique
behavior is only respected when dispatching through thePendingDispatch
class and theIlluminate\Console\Scheduling\Schedule
class (the latter fix was added in #39302). However, it is not respected when using theIlluminate\Bus\Dispatcher
class or individual queue drivers (Queue::push( ... )
, etc). This behavior can be confusing because depending on how you queue the job, it's easily possible to queue duplicates, despite the job implementingShouldBeUnique
I found a previous PR (#50381) that attempted to move the
ShouldBeUnique
check into theDispatcher
class. Although that still wouldn't guarantee uniqueness when usingQueue::push()
. I was also able to find some other issues which seem to indicate that people are generally expectingShouldBeUnique
to work universally:39113
45781
42297
48882
There's also a mention in the original PR for the
ShouldBeUnique
feature mentioning how this could possibly be moved into theenqueueUsing()
logic in theQueue
class? This seems like it would probably fix all of the above issuesFurther, the
Dispatcher
class and QueueenqueueUsing()
method already check other "expressive" interfaces likeShouldQueue
,ShouldQueueAfterCommit
, etc, so it seems reasonable to also checkShouldBeUnique
thereI would be willing to open a PR for this if desired. Was hesitant to do so as a similar PR (#50381) has already been closed
Steps To Reproduce
Create a job which implements
ShouldBeUnique
Confirm that
ShouldBeUnique
works correctly when usingPendingDispatch
. In tinkerConfirm that using
Queue::push(new UniqueJob())
,app(Dispatcher::class)->dispatch(new UniqueJob())
,Bus::dispatch(new UniqueJob())
do not work the same way