Horizon - Jobs with unique ID repeating when using batches
Hi there,
When dispatching a batch with jobs containing the same unique ID, we can see numerous instances of the job in the Pending jobs lists on Laravel Horizon. Our expected behaviour is for jobs with the same unique ID not to be added to the queue at the same time.
We have implemented ShouldBeUnique, defined a unique ID, and used Redis as the cache driver.
It works correctly without using batches:
// Restrics to only one job per uniqueId:
foreach ($tests as $test) {
TestJob::dispatch();
}
// Repeats jobs with same uniqueId:
$batch = [];
foreach ($tests as $test) {
$batch[] = new TestJob();
}
Bus::batch($batch)
->onConnection('redis')
->dispatch();
Thanks for the quick reply @hupp ! I've updated the post with more information regarding batches vs single dispatches. The issue only happens with batches.
I also tried to find more information about "should_be_unique_for" in the horizon config, but couldn't find any information about it.