sidekiq-unique-jobs: Question about until_timeout with 6.0.0
Formerly with 5.0.10 I had a job that did this:
unique: :until_timeout,
lock_expiration: 1.minute.to_i,
It’s a little unclear but looking at the updated readme & pr’s, the correct options in 6.0.0 is:
lock: :until_expired,
lock_expiration: 1.minute.to_i,
The goal is to have a job that will execute not more often than once a minute, given identical args. Eg,
Whatever.perform_async id: 1, group: 'x' # => job executes
Whatever.perform_async id: 2, group: 'a' # => job executes
Whatever.perform_async id: 1, group: 'x' # => discarded
Whatever.perform_async id: 1, group: 'x' # => discarded
# wait at least 1 minute
Whatever.perform_async id: 1, group: 'x' # => job executes
Is that correct?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 19 (11 by maintainers)
Okay, I have a new example that does not use
sleep
, in case that was affecting the expiration logic.Not using unique args:
In
rails c
I just hitup arrow
andenter
once per second for a few seconds to re-run the perform_async on a cadence:sidekiq:
The output is the same: execute, skip, skip, skip, skip, skip. I’m not super concerned about precise millisecond expirations, but hopefully you agree that at least job
15136b41cb19042e3a0bcd23
should have executed (the last one) since it’s much later than 3 seconds after the first job.I can tell that it can unlock, so I recognize that. Here’s another test where I ran 3 jobs quickly, waited a few seconds, then ran it one more time. I expected: execute, skip, skip, execute and that is what happened.
It’s almost like the lock is being taken out even when a job is a duplicate, and then released on schedule. That could explain why a repeated cadence of once per second is continually skipping execution, whereas explicitly waiting until the expiration window has passed will successfully execute the job.
@aharpervc found the bug. The UntilExpired was missing some coverage unfortunately, I’ll have it fixed shortly.