Also some logs from Horizon:
{ uniqueFor: 3600, timeout: 3600, id: 86, job: null, connection: null, queue: "delivery:push-manual-campaign-to-personalize", chainConnection: null, chainQueue: null, chainCatchCallbacks: null, delay: null, afterCommit: null, middleware: [ ], chained: [ ] }
{ uniqueFor: 3600, id: 86, job: null, connection: null, queue: "delivery:push-manual-campaign-to-personalize", chainConnection: null, chainQueue: null, chainCatchCallbacks: null, delay: null, afterCommit: null, middleware: [ ], chained: [ ] }
I see the difference that the second job has no timeout
Have you implemented Illuminate\Contracts\Queue\ShouldBeUnique
to your job? Like this:
use Illuminate\Contracts\Queue\ShouldBeUnique;
class UpdateSearchIndex implements ShouldQueue, ShouldBeUnique
{
// ...
}
Remind that any other job will be dispatched if the previous one is completed, so did you check timestamps of your jobs?
So, any new dispatches of the job with the same product ID will be ignored until the existing job has completed processing. In addition, if the existing job is not processed within one hour, the unique lock will be released and another job with the same unique key can be dispatched to the queue.
Thanks for the answer!
Yes, I did that. However, I noticed that my CACHE_DRIVER was set to file. Docs says that the 'File' driver also supports atomic locking, but I think it could be something regarding that. Do you think that might be the reason?
Also, I'm aware that a job can be dispatched after it gets completed, but this wasn't the case as far as I can remember. The biggest problem is that it's hard to replicate. I switched to Redis, it didn't happen again, but we'll see.
Anyway, I think I'll add something like this as an additional layer of protection.
$lock = Cache::lock('some-unique-id' 900);
if (!$lock->get()) {
return;
}
This is important to me because it can produce additional costs too. It's about sending emails and SMS.
theraloss liked this reply
Honestly I don't know if there are issues with File
driver, glad that Redis solves it (apparently) :)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community