Job lifecycle states, JSON types and the queue protocol with its errors. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
29 lines
672 B
Python
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
|