Repository navigation
Job cancellation #88
Replies: 6 comments 1 reply
|
@colingavin Moved to the ideas - discussion section. Its a feature that has been requested a few times, and im open to all the help i can get. But my vision for pgqueuer is to keep this library slim and easy to maintain, but yet useful. I think my main concern is that i think its a bad idea to just invoke the The simplest way i can think of is to introduce a 'checkpoint object (co)', the checkpoint object will be know if the a current job id should be canceled. Leaving up to the specific entrypoint function to know at what points its 'safe' to be canceled. |
|
Great - thanks for the quick reply. I agree on your point about the risk of directly cancelling tasks, especially since existing API users may not have written their entrypoints to expect cancellation. I would propose the following as general guidelines regarding cancellation behavior:
Does that sound reasonable to you? Open questions:
|
|
I've moved over to number references, hopefully making thins a bit easier to split up as there are few ongoing topics. Guidelines cancellation behavior
To me only open question (for now) is how do we add an extra argument to the entrypoint functions without breaking them. Open questions
|
The entrypoints already get a
For my use case, yes, most jobs will not be cancelled. Cancellation will be the exceptional case which would be triggered by user actions. In my particular case, a user would be starting a higher level task which may queue many individual jobs with Given this, how about roughly this design for the new APIs:
async def cancel_jobs(self, jobs: list[models.JobId]) -> NoneImmediately moves jobs that are in the
def cancel_scope_for_job(self, job_id: models.JobId) -> anyio.CancelScopeAllows an entrypoint to fetch a
@qm.entrypoint("task")
async def task(job: Job):
with qm.cancel_scope_for_job(job.id):
try:
await do_some_work() # may raise `asyncio.CancelledError`
finally:
cleanup() # can clean up from cancellation here
@qm.entrypoint("task")
def task(job: Job): # explicit checkpoints can also be used in non-async entrypoints
scope = qm.cancel_scope_for_job(job.id)
for x in subtasks:
if scope.cancel_called:
return
process(x) |
Uh oh!
There was an error while loading. Please reload this page.
I'm investigating using this package in a project that would require the ability to cancel queued jobs. In particular, I would like to be able to:
Is this a feature that would be in scope to support? If so, I'd be interested in getting your approval on a design and supplying a PR.
All reactions