steinitzu / celery-singleton

Seamlessly prevent duplicate executions of celery tasks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

lock by task name only

dedfriedly opened this issue · comments

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.

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.

👍