procrastinate
procrastinate copied to clipboard
Get the already enqueued task ID/PK on AlreadyEnqueued exception
Hey guys -
This question is regarding queueing locks and AlreadyEnqueued errors.
It would be really cool (!!) if we could do something like:
try:
enqueue_a_task_and_block()
except AlreadyEnqueued as e:
tid = e.args[0] # the already-enqueued task's ID/PK
await check_task_is_completed(tid) # this function blocks application code from continuing until the task is done, perhaps
Would it be possible to get the already enqueued task's ID on the exception instance? Is this already available somehow? Thanks!
I think it's kind of like https://github.com/peopledoc/procrastinate/issues/370 ? Do you confirm ?
Ah or is it about updating the exception to attach information on the task that is blocked ?
Ah or is it about updating the exception to attach information on the task that is blocked ?
Yea, this! The context is that we have some spots in our application code that need to block until a particular task completes. With queueing locks, we may try to enqueue some task, only to discover that for some reason that task has already been enqueued. In this case, the application code (Python ASGI web app) should wait for the existing task to complete.
This is a valid usecase. You could also use normal locks instead of queuing locks, and have your task check at the beginning if it hasn't actually been done and exit immediately if so.
I thought it would be a "simple" matter of improving the exception, but it might require changing SQL a bit. Not sure though.
I thought it would be a "simple" matter of improving the exception, but it might require changing SQL a bit. Not sure though.
Yes it will definitely require changing some SQL as far as I can tell. I'm not sure if Postgres provides a way to identify the conflicting record's PK/ID when some constraint is violated... but that would be great if so!