-
Let’s say I have a task called I think an analogous operation would be a database migration. For example, the framework (e.g. Django) checks the migrations table and only runs the migration 0002.py if it has no record of doing so. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Procrastinate jobs are kept in a table, much like the migration table. Here's a short run-down of how it works, with links to the relevant code. Note also that there are things explained on this page: https://procrastinate.readthedocs.io/en/stable/discussions.html There is a table named "procrastinate_jobs": A task is associated with a status: procrastinate/procrastinate/sql/schema.sql Lines 7 to 12 in c6e3aee When you defer a job, you launch this query: Which will always create the row with status todo. In order for a job to be taken and executed, it always goes through procrastinate/procrastinate/sql/schema.sql Lines 155 to 179 in c6e3aee Simplifying this query: WITH job as (
SELECT * from procrastinate_jobs
WHERE status = 'todo' and {job not blocked by another condition}
FOR UPDATE ORDER BY id LIMIT 1
)
UPDATE procrastinate_jobs
SET status = 'doing'
WHERE id = job.id The If the task never finishes, Procrastinate itself will not declare that the task is lost. There's currently no mechanism inside procrastinate for setting stale tasks as error, but you can create yours. There is something that will retry tasks under certain conditions if you declare you want them to retry (by default, they don't) if they finish with an exception during execution. Once a task finishes, we set its status to Of course there are a lot of ways things can go wrong which would leave the system in a state where it's impossible to know if a task has been executed or not. The If you think this is not enough, and you have both suggestions on how to improve it and the time to make PRs, I'll gladly listen. So far, anything we've envisioned for going further would be etiher architecturally unsatisfactory, too complex, or too dependent on user-code (or better implemented by client-code itself) |
Beta Was this translation helpful? Give feedback.
Procrastinate jobs are kept in a table, much like the migration table. Here's a short run-down of how it works, with links to the relevant code.
Note also that there are things explained on this page: https://procrastinate.readthedocs.io/en/stable/discussions.html
There is a table named "procrastinate_jobs":
procrastinate/procrastinate/sql/schema.sql
Line 26 in c6e3aee
A task is associated with a status:
procrastinate/procrastinate/sql/schema.sql
Lines 7 to 12 in c6e3aee