Chiusura fase di ristrutturazione e modularizzazione del workflow per favorire sviluppo modulare
This commit is contained in:
@@ -9,6 +9,7 @@ import re
|
||||
import stat
|
||||
from pathlib import Path
|
||||
from types import TracebackType
|
||||
from typing import Self
|
||||
|
||||
|
||||
class JobAlreadyRunningError(RuntimeError):
|
||||
@@ -34,7 +35,7 @@ class WorkspaceJobLock:
|
||||
)
|
||||
self._fd: int | None = None
|
||||
|
||||
def acquire(self) -> "WorkspaceJobLock":
|
||||
def acquire(self) -> WorkspaceJobLock:
|
||||
if self._fd is not None:
|
||||
raise RuntimeError("job lock is already held by this object")
|
||||
root_fd = os.open(self.path.parents[2], os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW)
|
||||
@@ -85,7 +86,7 @@ class WorkspaceJobLock:
|
||||
finally:
|
||||
os.close(fd)
|
||||
|
||||
def __enter__(self) -> "WorkspaceJobLock":
|
||||
def __enter__(self) -> Self:
|
||||
return self.acquire()
|
||||
|
||||
def __exit__(
|
||||
|
||||
@@ -7,8 +7,14 @@ from datetime import UTC, datetime
|
||||
from pathlib import Path
|
||||
from typing import Literal, Self
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_serializer, field_validator, model_validator
|
||||
|
||||
from pydantic import (
|
||||
BaseModel,
|
||||
ConfigDict,
|
||||
Field,
|
||||
field_serializer,
|
||||
field_validator,
|
||||
model_validator,
|
||||
)
|
||||
|
||||
_JOB_KEY = re.compile(r"^[a-z][a-z0-9_-]{0,63}$")
|
||||
_RUN_ID = re.compile(r"^[0-9a-f]{32}$")
|
||||
@@ -95,7 +101,7 @@ class JobSpec(_FrozenModel):
|
||||
data.update(update)
|
||||
return type(self).model_validate(data)
|
||||
|
||||
def with_resume(self, run_id: str) -> "JobSpec":
|
||||
def with_resume(self, run_id: str) -> JobSpec:
|
||||
return self.model_copy(update={"resume_run_id": run_id})
|
||||
|
||||
|
||||
@@ -121,7 +127,7 @@ class StageRun(_FrozenModel):
|
||||
)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def state_shape(self) -> "StageRun":
|
||||
def state_shape(self) -> StageRun:
|
||||
if self.status == "pending" and any(
|
||||
value is not None for value in (
|
||||
self.started_at, self.finished_at, self.error, self.effect_state,
|
||||
@@ -179,7 +185,7 @@ class JobRun(_FrozenModel):
|
||||
_resumed_from = field_validator("resumed_from")(_validate_run_id)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def ledger_shape(self) -> "JobRun":
|
||||
def ledger_shape(self) -> JobRun:
|
||||
names = [stage.name for stage in self.stages]
|
||||
if len(names) != len(set(names)):
|
||||
raise ValueError("stage identifiers must be unique")
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import uuid
|
||||
import stat
|
||||
import shutil
|
||||
import stat
|
||||
import uuid
|
||||
from collections.abc import Callable, Sequence
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
@@ -325,7 +325,7 @@ def run_job(
|
||||
_persist(checkpoint_path, run)
|
||||
try:
|
||||
stage_result = stage_callable(context)
|
||||
except Exception:
|
||||
except Exception: # noqa: BLE001 - stage failures are persisted as terminal reports
|
||||
failed = stage.model_copy(
|
||||
update={
|
||||
"status": "failed",
|
||||
|
||||
Reference in New Issue
Block a user