-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
33 lines (27 loc) · 923 Bytes
/
models.py
File metadata and controls
33 lines (27 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from dataclasses import dataclass
from typing import Literal
from job_executor.adapter import datastore_api
from job_executor.adapter.datastore_api.models import Job
from job_executor.adapter.fs import LocalStorageAdapter
handler_type = Literal["worker"] | Literal["manager"]
@dataclass
class JobContext:
job: Job
handler: handler_type
local_storage: LocalStorageAdapter
job_size: int | None = None
def build_job_context(job: Job, handler: handler_type) -> JobContext:
local_storage = LocalStorageAdapter(
datastore_api.get_datastore_directory(job.datastore_rdn),
job.datastore_rdn,
)
job_size = (
local_storage.input_dir.get_importable_tar_size_in_bytes(
job.parameters.target
)
if handler == "worker"
else None
)
return JobContext(
job=job, handler=handler, local_storage=local_storage, job_size=job_size
)