steinitzu / celery-singleton

Seamlessly prevent duplicate executions of celery tasks
MIT License
237 stars 36 forks source link

lock by task name only #15

Closed dedfriedly closed 3 years ago

dedfriedly commented 4 years ago

Hi, loving this project and had a unique use case that I don't believe thru my testing is covered here just yet.

The summary is pretty simple, I just wanted to lock a task to only it's task name. I tested with the unique decorator arg but I couldn't get it to work as expected.

I did end up getting something to work by forking + modifying. Essentially two minor changes, I added a unique_on keyword such that if unique_on == 'none' then it'll run a task hash for only the task name (no args or kwargs). I then set a self.lock_id variable on the object and use this in the release, unlock, etc functions versus rehashing the key.

steinitzu commented 4 years ago

You're right there's now way to do this right now.
Rather than passing a magic 'none' string I would make unique_on accept an empty list/sequence to mean "ignore all arguments".
Currently unique_on is ignored with any falsy value, but should be a simple change.

dedfriedly commented 4 years ago

👍