Skip to content

Commit 5fc95e9

Browse files
authored
Add extra field to job model (#178)
1 parent 80203f1 commit 5fc95e9

File tree

6 files changed

+63
-0
lines changed

6 files changed

+63
-0
lines changed

aiohasupervisor/models/jobs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from dataclasses import dataclass
66
from datetime import datetime # noqa: TCH003
77
from enum import StrEnum
8+
from typing import Any
89
from uuid import UUID # noqa: TCH003
910

1011
from .base import Request, ResponseData
@@ -61,6 +62,7 @@ class Job(ResponseData):
6162
errors: list[JobError]
6263
created: datetime
6364
child_jobs: list[Job]
65+
extra: dict[str, Any] | None
6466

6567

6668
@dataclass(slots=True, frozen=True)

tests/fixtures/jobs_get_job.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"done": true,
1010
"errors": [],
1111
"created": "2025-01-30T20:55:12.859349+00:00",
12+
"extra": null,
1213
"child_jobs": [
1314
{
1415
"name": "backup_store_folders",
@@ -19,6 +20,7 @@
1920
"done": true,
2021
"errors": [],
2122
"created": "2025-01-30T20:55:12.892008+00:00",
23+
"extra": null,
2224
"child_jobs": [
2325
{
2426
"name": "backup_folder_save",
@@ -29,6 +31,7 @@
2931
"done": true,
3032
"errors": [],
3133
"created": "2025-01-30T20:55:12.892699+00:00",
34+
"extra": null,
3235
"child_jobs": []
3336
}
3437
]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"result": "ok",
3+
"data": {
4+
"name": "docker_interface_install",
5+
"reference": "homeassistant",
6+
"uuid": "2febe59311f94d6ba36f6f9f73357ca8",
7+
"progress": 0,
8+
"stage": null,
9+
"done": false,
10+
"errors": [],
11+
"created": "2025-01-30T20:55:12.859349+00:00",
12+
"extra": null,
13+
"child_jobs": [
14+
{
15+
"name": "Pulling container image layer",
16+
"reference": "1e214cd6d7d0",
17+
"uuid": "f4bac7d9240f434a9f6a21aff7f7ade3",
18+
"progress": 26.1,
19+
"stage": "Downloading",
20+
"done": false,
21+
"errors": [],
22+
"created": "2025-01-30T20:55:12.892008+00:00",
23+
"extra": {
24+
"current": 227726144,
25+
"total": 436480882
26+
},
27+
"child_jobs": []
28+
}
29+
]
30+
}
31+
}

tests/fixtures/jobs_info.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"done": true,
1313
"errors": [],
1414
"created": "2025-01-30T20:55:12.859349+00:00",
15+
"extra": null,
1516
"child_jobs": [
1617
{
1718
"name": "backup_store_folders",
@@ -22,6 +23,7 @@
2223
"done": true,
2324
"errors": [],
2425
"created": "2025-01-30T20:55:12.892008+00:00",
26+
"extra": null,
2527
"child_jobs": [
2628
{
2729
"name": "backup_folder_save",
@@ -32,6 +34,7 @@
3234
"done": true,
3335
"errors": [],
3436
"created": "2025-01-30T20:55:12.892699+00:00",
37+
"extra": null,
3538
"child_jobs": []
3639
}
3740
]
@@ -53,6 +56,7 @@
5356
}
5457
],
5558
"created": "2025-01-30T20:55:15.000000+00:00",
59+
"extra": null,
5660
"child_jobs": []
5761
}
5862
]

tests/fixtures/jobs_info_no_stage.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
}
1919
],
2020
"created": "2025-01-30T20:55:12.859349+00:00",
21+
"extra": null,
2122
"child_jobs": []
2223
}
2324
]

tests/test_jobs.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,28 @@ async def test_jobs_get_job(
9797
assert info.child_jobs[0].child_jobs[0].child_jobs == []
9898

9999

100+
async def test_jobs_get_job_extra(
101+
responses: aioresponses, supervisor_client: SupervisorClient
102+
) -> None:
103+
"""Test jobs get job API with extra metadata."""
104+
responses.get(
105+
f"{SUPERVISOR_URL}/jobs/2febe59311f94d6ba36f6f9f73357ca8",
106+
status=200,
107+
body=load_fixture("jobs_get_job_extra.json"),
108+
)
109+
info = await supervisor_client.jobs.get_job(
110+
UUID("2febe59311f94d6ba36f6f9f73357ca8")
111+
)
112+
113+
assert info.name == "docker_interface_install"
114+
assert info.reference == "homeassistant"
115+
assert info.child_jobs[0].name == "Pulling container image layer"
116+
assert info.child_jobs[0].reference == "1e214cd6d7d0"
117+
assert info.child_jobs[0].progress == 26.1
118+
assert info.child_jobs[0].stage == "Downloading"
119+
assert info.child_jobs[0].extra == {"current": 227726144, "total": 436480882}
120+
121+
100122
async def test_jobs_delete_job(
101123
responses: aioresponses, supervisor_client: SupervisorClient
102124
) -> None:

0 commit comments

Comments
 (0)