`on_locked_action` is not triggered if job is not `locked?` but `lock!` fails
Closed this issue · 1 comments
wamaral commented
When calling enqueue
, locked?
will check the existence of the key in Redis, and if it's not present will then call lock!
These two calls (locked?
and lock!
) are not atomic, so a lock could be acquired in the meantime, and the lock!
would fail. However, in this case we're not calling the on_locked_action
method
It sounds like we should, but maybe there are some implications that I haven't considered (ex: should we call on_locked_action
if Redis is offline?). Thoughts?
plcstevens commented
IMO: If Redis is dead, we should crash.
def enqueue(options = {})
@options = options
return trigger_on_locked_action if locked?
return trigger_on_locked_action unless lock!
super(options)
end
private
def trigger_on_locked_action
logger.info "job is locked, expires in #{locked_ttl} second"
send(on_locked_action) if on_locked_action && respond_to?(on_locked_action)
nil
end
One option would be to handle the lock!
return value