refactor(schedule): add domain/ package files
Add the three files that complete stage 1 of the layered refactor:
- schedule/src/schedule/domain/__init__.py (empty package marker)
- schedule/src/schedule/domain/context.py
(TERMINAL_NODE_STATES / FAILED_NODE_STATES / TERMINAL_RUN_STATES / naive_utc —
pure types, no I/O)
- schedule/src/schedule/domain/execution.py
(ExecutionResult dataclass, frozen=True)
The corresponding import-path rewrites in worker.py / orchestrator.py /
scheduler.py / execution.py were already landed in cdcfcb2 (the prior
commit on this branch). This commit only adds the missing domain/
package files those imports point at.
Validation:
- uv run --package schedule pytest schedule/tests -q: 18 passed
- uv run python -m compileall schedule/src: zero errors
- from schedule.domain.context / schedule.domain.execution importable
- main.py / pyproject.toml / tests/ unchanged
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
"""Shared constants and timezone helpers for the scheduler components.
|
||||
|
||||
Designed to be import-side-effect-free: no logging, no I/O, no model imports.
|
||||
Used by ``scheduler``, ``orchestrator`` and ``worker`` modules.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import UTC, datetime
|
||||
|
||||
TERMINAL_NODE_STATES = frozenset({
|
||||
"succeeded",
|
||||
"failed",
|
||||
"skipped",
|
||||
"cancelled",
|
||||
"timed_out",
|
||||
})
|
||||
FAILED_NODE_STATES = frozenset({"failed", "cancelled", "timed_out"})
|
||||
TERMINAL_RUN_STATES = frozenset({
|
||||
"succeeded",
|
||||
"failed",
|
||||
"cancelled",
|
||||
"timed_out",
|
||||
})
|
||||
|
||||
|
||||
def naive_utc(value: datetime | None) -> datetime | None:
|
||||
"""Normalize a datetime to naive UTC; pass through ``None``."""
|
||||
if value is None:
|
||||
return None
|
||||
if value.tzinfo is None:
|
||||
value = value.replace(tzinfo=UTC)
|
||||
return value.astimezone(UTC).replace(tzinfo=None)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"FAILED_NODE_STATES",
|
||||
"TERMINAL_NODE_STATES",
|
||||
"TERMINAL_RUN_STATES",
|
||||
"naive_utc",
|
||||
]
|
||||
@@ -0,0 +1,21 @@
|
||||
"""Domain types for schedule node execution.
|
||||
|
||||
Pure value objects — no I/O, no logging, no model imports. Safe to import
|
||||
from any layer.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class ExecutionResult:
|
||||
status: str
|
||||
exit_code: int | None
|
||||
logs: bytes
|
||||
result: bytes
|
||||
result_file_name: str
|
||||
result_content_type: str
|
||||
error_code: str | None = None
|
||||
error_message: str | None = None
|
||||
Reference in New Issue
Block a user