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>
This commit is contained in:
torbenandClaude Sonnet 5.5 committed 2026-12-03 23:32:22 +01:00
1 parent 776cef7bc3
commit cef1a48b69
2 files changed
+68

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
"""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