Skip to content

Commit f5dc1f5

Browse files
authored
Merge pull request #1388 from procrastinate-org/fix-json
2 parents c9a1c69 + 988f31c commit f5dc1f5

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ docs/_build
1313
htmlcov
1414
VERSION.txt
1515
.benchmarks
16+
.python-version

procrastinate/types.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
from __future__ import annotations
22

33
import datetime
4-
import typing as t
4+
from typing import NamedTuple, TypedDict
55

6-
from typing_extensions import NotRequired
6+
from typing_extensions import NotRequired, TypeAlias
77

8-
JSONValue = t.Union[str, int, float, bool, None, dict[str, t.Any], list[t.Any]]
8+
JSONValue: TypeAlias = (
9+
'dict[str, "JSONValue"] | list["JSONValue"] | str | int | float | bool | None'
10+
)
911
JSONDict = dict[str, JSONValue]
1012

1113

12-
class TimeDeltaParams(t.TypedDict):
14+
class TimeDeltaParams(TypedDict):
1315
weeks: NotRequired[int]
1416
days: NotRequired[int]
1517
hours: NotRequired[int]
@@ -19,7 +21,7 @@ class TimeDeltaParams(t.TypedDict):
1921
microseconds: NotRequired[int]
2022

2123

22-
class JobToDefer(t.NamedTuple):
24+
class JobToDefer(NamedTuple):
2325
queue_name: str
2426
task_name: str
2527
priority: int

procrastinate/worker.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,15 @@ def _log_extra(
113113
job_result: job_context.JobResult | None,
114114
**kwargs: Any,
115115
) -> types.JSONDict:
116+
worker: types.JSONDict = {
117+
"name": self.worker_name,
118+
"worker_id": self.worker_id,
119+
"job_id": context.job.id if context else None,
120+
"queues": list(self.queues or []),
121+
}
116122
extra: types.JSONDict = {
117123
"action": action,
118-
"worker": {
119-
"name": self.worker_name,
120-
"worker_id": self.worker_id,
121-
"job_id": context.job.id if context else None,
122-
"queues": self.queues,
123-
},
124+
"worker": worker,
124125
}
125126
if context:
126127
extra["job"] = context.job.log_context()

tests/integration/test_manager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import asyncio
34
import datetime
45
import functools
56

@@ -315,6 +316,7 @@ async def test_get_stalled_jobs_by_heartbeat__pruned_worker(
315316

316317
async def test_register_and_unregister_worker(pg_job_manager, psycopg_connector):
317318
then = utils.utcnow()
319+
await asyncio.sleep(0)
318320
worker_id = await pg_job_manager.register_worker()
319321
assert worker_id is not None
320322

0 commit comments

Comments
 (0)