Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get the already enqueued task ID/PK on AlreadyEnqueued exception #452

Open
mecampbellsoup opened this issue Sep 22, 2021 · 5 comments
Open
Labels
Issue appropriate for: Occasional contributors 😉 This issue will be best tackled by people with a minimum of experience on the project Issue contains: Some Python 🐍 This issue involves writing some Python code Issue contains: Some SQL 🐘 This features require changing the SQL model

Comments

@mecampbellsoup
Copy link
Contributor

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!

@ewjoachim
Copy link
Member

ewjoachim commented Sep 23, 2021

I think it's kind of like #370 ? Do you confirm ?

Ah or is it about updating the exception to attach information on the task that is blocked ?

@mecampbellsoup
Copy link
Contributor Author

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.

@ewjoachim
Copy link
Member

ewjoachim commented Sep 23, 2021

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.

@ewjoachim ewjoachim added Issue appropriate for: newcomers 🤩 This issue can be safely tackled by people who never worked in this project before Issue contains: Some Python 🐍 This issue involves writing some Python code Issue type: Feature Issue appropriate for: Occasional contributors 😉 This issue will be best tackled by people with a minimum of experience on the project Issue contains: Some SQL 🐘 This features require changing the SQL model and removed Issue appropriate for: newcomers 🤩 This issue can be safely tackled by people who never worked in this project before labels Sep 27, 2021
@ewjoachim
Copy link
Member

I thought it would be a "simple" matter of improving the exception, but it might require changing SQL a bit. Not sure though.

@ewjoachim ewjoachim changed the title Get the already enqueued task ID/PK on AlreadyEnqueued exception? Get the already enqueued task ID/PK on AlreadyEnqueued exception Sep 27, 2021
@mecampbellsoup
Copy link
Contributor Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue appropriate for: Occasional contributors 😉 This issue will be best tackled by people with a minimum of experience on the project Issue contains: Some Python 🐍 This issue involves writing some Python code Issue contains: Some SQL 🐘 This features require changing the SQL model
Projects
None yet
Development

No branches or pull requests

2 participants