-
-
Notifications
You must be signed in to change notification settings - Fork 110
Add result to jobs #1502
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
base: main
Are you sure you want to change the base?
Add result to jobs #1502
Changes from all commits
e3dc095
a940c04
218e390
d495df3
3a6c15e
826633e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,7 +10,12 @@ | |||||||||||||||||||||||
| [](https://github.com/procrastinate-org/procrastinate/blob/main/CODE_OF_CONDUCT.md) | ||||||||||||||||||||||||
| [](https://discord.gg/JWZeNq6P6Z) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| **Procrastinate is looking for** [additional maintainers!](https://github.com/procrastinate-org/procrastinate/discussions/748) | ||||||||||||||||||||||||
| ### Fork changes | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| 1. Added `result` column to `jobs` table so failed job can store it's failure reason | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| **Procrastinate is looking for | ||||||||||||||||||||||||
| ** [additional maintainers!](https://github.com/procrastinate-org/procrastinate/discussions/748) | ||||||||||||||||||||||||
|
Comment on lines
+13
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix heading level and malformed bold markdown. Two issues:
📝 Suggested fix-### Fork changes
+## Fork changes
1. Added `result` column to `jobs` table so failed job can store it's failure reason
-**Procrastinate is looking for
-** [additional maintainers!](https://github.com/procrastinate-org/procrastinate/discussions/748)
+**Procrastinate is looking for [additional maintainers!](https://github.com/procrastinate-org/procrastinate/discussions/748)**📝 Committable suggestion
Suggested change
🧰 Tools🪛 LanguageTool[style] ~18-~18: Using many exclamation marks might seem excessive (in this case: 8 exclamation marks for a text that’s 3189 characters long) (EN_EXCESSIVE_EXCLAMATION) 🪛 markdownlint-cli2 (0.20.0)[warning] 13-13: Heading levels should only increment by one level at a time (MD001, heading-increment) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Procrastinate is an open-source Python 3.10+ distributed task processing | ||||||||||||||||||||||||
| library, leveraging PostgreSQL 13+ to store task definitions, manage locks and | ||||||||||||||||||||||||
|
|
@@ -31,12 +36,14 @@ import procrastinate | |||||||||||||||||||||||
| # Make an app in your code | ||||||||||||||||||||||||
| app = procrastinate.App(connector=procrastinate.SyncPsycopgConnector()) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # Then define tasks | ||||||||||||||||||||||||
| @app.task(queue="sums") | ||||||||||||||||||||||||
| def sum(a, b): | ||||||||||||||||||||||||
| with open("myfile", "w") as f: | ||||||||||||||||||||||||
| f.write(str(a + b)) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| with app.open(): | ||||||||||||||||||||||||
| # Launch a job | ||||||||||||||||||||||||
| sum.defer(a=3, b=5) | ||||||||||||||||||||||||
|
|
@@ -72,11 +79,13 @@ import procrastinate | |||||||||||||||||||||||
| # Make an app in your code | ||||||||||||||||||||||||
| app = procrastinate.App(connector=procrastinate.PsycopgConnector()) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # Define tasks using coroutine functions | ||||||||||||||||||||||||
| @app.task(queue="sums") | ||||||||||||||||||||||||
| async def sum(a, b): | ||||||||||||||||||||||||
| await asyncio.sleep(a + b) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| async with app.open_async(): | ||||||||||||||||||||||||
| # Launch a job | ||||||||||||||||||||||||
| await sum.defer_async(a=3, b=5) | ||||||||||||||||||||||||
|
|
@@ -106,7 +115,11 @@ If you encounter a bug, or want to get in touch, you're always welcome to open a | |||||||||||||||||||||||
| [ticket]. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| [docs]: https://procrastinate.readthedocs.io/ | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| [procrastinate]: https://en.wikipedia.org/wiki/Procrastination | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| [django]: https://procrastinate.readthedocs.io/en/stable/howto/django/configuration.html | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| [quickstart]: https://procrastinate.readthedocs.io/en/stable/quickstart.html | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| [ticket]: https://github.com/procrastinate-org/procrastinate/issues/new | ||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from django.db import migrations | ||
|
|
||
| from .. import migrations_utils | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| operations = [ | ||
| migrations_utils.RunProcrastinateSQL( | ||
| name="03.08.00_01_pre_result_to_job_procedure.sql" | ||
| ), | ||
| ] | ||
| name = "0042_pre_result_column" | ||
| dependencies = [ | ||
| ("procrastinate", "0041_post_retry_failed_job"), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| ALTER TABLE procrastinate_jobs ADD COLUMN result TEXT; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| drop function if exists "public"."procrastinate_finish_job_v1"(job_id bigint, end_status procrastinate_job_status, delete_job boolean); | ||
|
|
||
|
|
||
| CREATE FUNCTION procrastinate_finish_job_v1(job_id bigint, end_status procrastinate_job_status, delete_job boolean, job_result text default null) | ||
| RETURNS void | ||
| LANGUAGE plpgsql | ||
| AS $$ | ||
| DECLARE | ||
| _job_id bigint; | ||
| BEGIN | ||
| IF end_status NOT IN ('succeeded', 'failed', 'aborted') THEN | ||
| RAISE 'End status should be either "succeeded", "failed" or "aborted" (job id: %)', job_id; | ||
| END IF; | ||
| IF delete_job THEN | ||
| DELETE FROM procrastinate_jobs | ||
| WHERE id = job_id AND status IN ('todo', 'doing') | ||
| RETURNING id INTO _job_id; | ||
| ELSE | ||
| UPDATE procrastinate_jobs | ||
| SET status = end_status, | ||
| abort_requested = false, | ||
| result = job_result, | ||
| attempts = CASE status | ||
| WHEN 'doing' THEN attempts + 1 ELSE attempts | ||
| END | ||
| WHERE id = job_id AND status IN ('todo', 'doing') | ||
| RETURNING id INTO _job_id; | ||
| END IF; | ||
| IF _job_id IS NULL THEN | ||
| RAISE 'Job was not found or not in "doing" or "todo" status (job id: %)', job_id; | ||
| END IF; | ||
| END; | ||
| $$ | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor grammatical issue: "it's" should be "its".
"it's" is a contraction of "it is", while "its" is the possessive form needed here.
📝 Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents