Closed medihack closed 1 month ago
Looking good. What about naming the column abort_requested
?
Alternatively, it could be a nullable timestamp abort_requested_at
that can be inferred as a flag but also conveys the time it is requested in the job table.
Looking good. What about naming the column
abort_requested
?
Yes, that sounds good. I renamed it to abort_requested
.
Alternatively, it could be a nullable timestamp
abort_requested_at
that can be inferred as a flag but also conveys the time it is requested in the job table.
For the sake of simplicity, I would keep it a boolean flag. I make sure that the event of an abortion request is recorded (and the event itself has a timestamp). Are you okay with that?
Click to see where and how coverage changed
File Statements Missing Coverage Coverage
(new stmts)Lines missing
procrastinate
job_context.py
manager.py
testing.py
worker.py
procrastinate/contrib/django
models.py
Project Total
This report was generated by python-coverage-comment-action
Some design decisions:
abort_requested
available on the Job
itself because if the user checks job.abort_requested
of a passed context inside a task (in contrast to calling should_abort
), this information is not up-to-date.abort_requested
to False
when the job is finished.
The migration becomes quite long as it is not possible to remove a value (in this case, aborting
) from an enum type. A new enum type must be created, the old one must be swapped out, and all dependencies (indexes, functions, trigger) must be recreated. I tried to add good comments to make things clear.I will switch the branch to merge against when we have a new branch for our beta.
The migration becomes quite long as it is not possible to remove a value (in this case, aborting) from an enum type. A new enum type must be created, the old one must be swapped out, and all dependencies (indexes, functions, trigger) must be recreated. I tried to add good comments to make things clear.
That is the main drawback of postgres enum
. They are not designed to have their values deleted
I haven't intentionally made abort_requested available on the Job itself because if the user checks job.abort_requested of a passed context inside a task (in contrast to calling should_abort), this information is not up-to-date.
And as long as the Job
class is marked as frozen, we can't simply change the flag.
Here is a thought on how the should_abort
could work:
The task doesn't call the database through the JobManager
.
Instead:
The worker maintains a set of the job ids that should be aborted.
The JobContext
exposes a function that returns True if the job id is in that set.
This means the tasks can check through the JobContext
without introducing database overhead.
For async task, the worker could call cancel
on the asyncio Task. The user code can then handle CancellationError
to control abortion.
Here is a thought on how the
should_abort
could work:The task doesn't call the database through the
JobManager
. Instead:
- a side task from the worker polls the database at a configured interval for any job that should be aborted (and it would only be interested in the jobs that it currently runs)
- additionally, a listener is notified every time a job is requested to be aborted which provides low latency.
The worker maintains a set of the job ids that should be aborted. The
JobContext
exposes a function that returns True if the job id is in that set.This means the tasks can check through the
JobContext
without introducing database overhead.For async task, the worker could call
cancel
on the asyncio Task. The user code can then handleCancellationError
to control abortion.
Yes, that all sounds reasonable. But let's start by getting this PR (as it is) in the v3 branch, then the worker refactoring, and then start from there. At least we have a solid base, then. @ewjoachim Do you agree?
I agree. @onlyann your proposal seems to match what #1084 describes.
(is the PR ready for review after the worker refactor ?)
(is the PR ready for review after the worker refactor ?)
Yes, I think so.
Closes #1136
Successful PR Checklist:
PR label(s):