From 6d2d09c3049b63ddcac23b5fa6a4c924e475fffd Mon Sep 17 00:00:00 2001 From: Joachim Jablon Date: Sat, 10 May 2025 15:02:11 +0200 Subject: [PATCH 1/3] Make the JSONValue type recursive --- procrastinate/types.py | 12 +++++++----- procrastinate/worker.py | 13 +++++++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/procrastinate/types.py b/procrastinate/types.py index 5da2e29bb..15e229951 100644 --- a/procrastinate/types.py +++ b/procrastinate/types.py @@ -1,15 +1,17 @@ from __future__ import annotations import datetime -import typing as t +from typing import NamedTuple, TypedDict -from typing_extensions import NotRequired +from typing_extensions import NotRequired, TypeAlias -JSONValue = t.Union[str, int, float, bool, None, dict[str, t.Any], list[t.Any]] +JSONValue: TypeAlias = ( + 'dict[str, "JSONValue"] | list["JSONValue"] | str | int | float | bool | None' +) JSONDict = dict[str, JSONValue] -class TimeDeltaParams(t.TypedDict): +class TimeDeltaParams(TypedDict): weeks: NotRequired[int] days: NotRequired[int] hours: NotRequired[int] @@ -19,7 +21,7 @@ class TimeDeltaParams(t.TypedDict): microseconds: NotRequired[int] -class JobToDefer(t.NamedTuple): +class JobToDefer(NamedTuple): queue_name: str task_name: str priority: int diff --git a/procrastinate/worker.py b/procrastinate/worker.py index 04ced0620..01351ae86 100644 --- a/procrastinate/worker.py +++ b/procrastinate/worker.py @@ -113,14 +113,15 @@ def _log_extra( job_result: job_context.JobResult | None, **kwargs: Any, ) -> types.JSONDict: + worker: types.JSONDict = { + "name": self.worker_name, + "worker_id": self.worker_id, + "job_id": context.job.id if context else None, + "queues": list(self.queues or []), + } extra: types.JSONDict = { "action": action, - "worker": { - "name": self.worker_name, - "worker_id": self.worker_id, - "job_id": context.job.id if context else None, - "queues": self.queues, - }, + "worker": worker, } if context: extra["job"] = context.job.log_context() From a4d5ceca446a792af887ec815a7b15de876617be Mon Sep 17 00:00:00 2001 From: Joachim Jablon Date: Sat, 10 May 2025 15:37:36 +0200 Subject: [PATCH 2/3] Fix a test failing because of microseconds --- tests/integration/test_manager.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/integration/test_manager.py b/tests/integration/test_manager.py index 60f0a099d..0cfe9b35d 100644 --- a/tests/integration/test_manager.py +++ b/tests/integration/test_manager.py @@ -1,5 +1,6 @@ from __future__ import annotations +import asyncio import datetime import functools @@ -315,6 +316,7 @@ async def test_get_stalled_jobs_by_heartbeat__pruned_worker( async def test_register_and_unregister_worker(pg_job_manager, psycopg_connector): then = utils.utcnow() + await asyncio.sleep(0) worker_id = await pg_job_manager.register_worker() assert worker_id is not None From 988f31cd695d8f6fc775fa6dcee099b4b95a0ca8 Mon Sep 17 00:00:00 2001 From: Joachim Jablon Date: Sat, 10 May 2025 15:37:56 +0200 Subject: [PATCH 3/3] Ignore .python-version --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 8cebc4a93..70cb23511 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ docs/_build htmlcov VERSION.txt .benchmarks +.python-version