Files
chemenu-ng/src/chemenu/domain/job.py
T
torbenandClaude Sonnet 5.5 cef1a48b69 Add Job domain type and JobQueue port
Job lifecycle states, JSON types and the queue protocol with its errors.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-12-03 23:32:22 +01:00

29 lines
672 B
Python

"""Job: a unit of queued work and its lifecycle state."""
from dataclasses import dataclass
from datetime import datetime
from enum import StrEnum
from uuid import UUID
type JsonValue = str | int | float | bool | list[JsonValue] | dict[str, JsonValue] | None
type JsonObject = dict[str, JsonValue]
class JobState(StrEnum):
QUEUED = "queued"
RUNNING = "running"
DONE = "done"
FAILED = "failed"
@dataclass(frozen=True, slots=True, kw_only=True)
class Job:
id: UUID
kind: str
payload: JsonObject
state: JobState
attempts: int
enqueued_at: datetime # aware, UTC
result: JsonObject | None = None
reason: str | None = None