resque-lock icon indicating copy to clipboard operation
resque-lock copied to clipboard

Unlock queue on dequeue

Open humancopy opened this issue 13 years ago • 2 comments

Unlocks a queue when dequeue is called, using the before dequeue hook (see: https://github.com/humancopy/resque/commit/5042244f486b8ee976926f4b4007de182718f0ef).

It also stores the lock in a hash so it's easier to remove all locks if needed.

There are still deadlocks happening when using Resque.remove_queue to remove the whole queue. Still thinking on this one... :)

humancopy avatar Sep 20 '11 20:09 humancopy

Still trying to think of a way to remove the locks when removing the whole queue. Since remove_queue is called on Resque and not on the queue's class itself, and it's not possible to get the class from the queue name - i'm stuck on this... :)

One way I thought to resolve this is to force the queue name on the lock. Something like this:

def lock_id
  "#{@queue}:#{lock}"
end

def lock(*args)
  args.to_s
end

Then in the code of Resque::Plugins::Lock call lock_id instead of lock, so lock can still be used to customize the lock's name.

And then still need to be able to add a hook on remove_queue of Resque class.

I can try to implement this, let me know if you're interested :)

humancopy avatar Sep 27 '11 19:09 humancopy

Hey ...

I've reverted back the hash change (for speed), so it now uses normal Redis keys again.

I also added another class method for defining if the lock should be lifted or kept for running jobs. It was required in one project where it was important for jobs with same args to get queued even if the same job is running. I called it lock_running?, though I think the name is not descriptive enough of it's use, but couldn't think of something better. Any ideas?

Enjoy ;)

humancopy avatar Mar 20 '12 18:03 humancopy