procrastinate
procrastinate copied to clipboard
Feature request: Allow `True` for `queueing_lock` and `lock`
For when you want to use locking within a single task, not shared with other locks, you now have to do:
@app.periodic(cron="* * * * *", queueing_lock="myapp.tasks.retry_stalled_jobs", lock="myapp.tasks.retry_stalled_jobs")
@app.task()
async def retry_stalled_jobs(timestamp: int):
stalled_jobs = await app.job_manager.get_stalled_jobs()
for job in stalled_jobs:
await app.job_manager.retry_job(job)
Would be nice if you could just do:
@app.periodic(cron="* * * * *", queueing_lock=True, lock=True)
And it would effectively use the task name as the lock.
Thoughts?
I am a bit hesitant to add this, as it ultimately just translates to a string and only deludes that it does something special. @ewjoachim What do you think?
Actually I would make it lock by all the kwargs. Is that special enough? :)
Also, if we want to have e.g. max one job for processing an entity and use the id as the lock (using a manual configure), won’t that explode the Django admin filter sidebar? Is this not an appropriate use of the feature?
I understand it all up until "I would make it lock by all the kwargs", especially applied to a periodic decorator where the 1st kwarg is the timestamp that will be different every time.
Also, if we want to have e.g. max one job for processing an entity and use the id as the lock (using a manual configure), won’t that explode the Django admin filter sidebar? Is this not an appropriate use of the feature?
Depending on how long tasks are kept in the DB after processing, yes possibly. It's certainly a shortcoming of the Django Admin but that's one of the ways the feature is meant to be used.
Maybe the @app.task([queueing_]lock=...) could take a lambda that receives kwargs and returns the lock name?
Effectively, I find it ugly to specify the lock names at the (potentially multiple) call sites using configure()... How the locking is done is IMO part of the task execution, not the enqueue operation, and I'd prefer to define it using @app. However that only works as long as you have a static string, i.e. really only one lock.
Maybe I'm missing something.