refactor: share expression traversal and history types

This commit is contained in:
lda
2026-09-10 02:16:38 +07:00 Verified
parent 93a6a03b9e
commit ed70223c1b
6 changed files with 60 additions and 51 deletions
+31 -22
View File
@@ -17,7 +17,7 @@ contains no fixture input, fixture environments, or canned results.
from __future__ import annotations
from datetime import datetime, timezone
from typing import Any
from typing import Any, cast
from wf_scheduling.calendar import (
CronSource,
@@ -31,7 +31,7 @@ from wf_scheduling.history import (
HistoryEntry,
HistoryRecorder,
)
from wf_scheduling.models import PendingCandidate
from wf_scheduling.models import OccurrenceKind, PendingCandidate
from wf_scheduling.ownership import (
SchedulerOwnership,
SecondOwnerError,
@@ -258,7 +258,7 @@ class Scheduler:
def _record(
self,
*,
kind: str,
kind: OccurrenceKind,
sched_id: str,
intended: datetime | None = None,
run_id: str | None = None,
@@ -275,7 +275,7 @@ class Scheduler:
self.history.record(
HistoryEntry(
schedule_id=sched_id,
kind=kind, # type: ignore[arg-type]
kind=kind,
resolved_at=intended,
run_id=run_id,
revision=revision,
@@ -504,13 +504,16 @@ class Scheduler:
run_id=run_id,
)
self.run_store.clear_executing(run_id)
kind = {
StoredRunStatus.COMPLETED: "completed",
StoredRunStatus.INTERRUPTED: "interrupted",
StoredRunStatus.FAILED: "failed",
}[stopped.status]
kind = cast(
OccurrenceKind,
{
StoredRunStatus.COMPLETED: "completed",
StoredRunStatus.INTERRUPTED: "interrupted",
StoredRunStatus.FAILED: "failed",
}[stopped.status],
)
self._record(
kind=kind, # type: ignore[arg-type]
kind=kind,
sched_id=admission.schedule_id,
intended=_admission_intended(self.run_store, run_id),
run_id=run_id,
@@ -563,13 +566,16 @@ class Scheduler:
run_id=run_id,
)
self.run_store.clear_executing(run_id)
kind = {
StoredRunStatus.COMPLETED: "completed",
StoredRunStatus.INTERRUPTED: "interrupted",
StoredRunStatus.FAILED: "failed",
}[stopped.status]
kind = cast(
OccurrenceKind,
{
StoredRunStatus.COMPLETED: "completed",
StoredRunStatus.INTERRUPTED: "interrupted",
StoredRunStatus.FAILED: "failed",
}[stopped.status],
)
self._record(
kind=kind, # type: ignore[arg-type]
kind=kind,
sched_id=admission.schedule_id,
intended=_admission_intended(self.run_store, run_id),
run_id=run_id,
@@ -597,11 +603,14 @@ class Scheduler:
history. Returns whether an entry was appended.
"""
self._require_ownership()
kind = {
"completed": "completed",
"interrupted": "interrupted",
"failed": "failed",
}.get(status_value)
kind = cast(
OccurrenceKind | None,
{
"completed": "completed",
"interrupted": "interrupted",
"failed": "failed",
}.get(status_value),
)
if kind is None:
return False
try:
@@ -614,7 +623,7 @@ class Scheduler:
if self.history.has_terminal(sched_id, run_id, kind, checkpoint_id):
return False
self._record(
kind=kind, # type: ignore[arg-type]
kind=kind,
sched_id=sched_id,
intended=admission.scheduled_at,
run_id=run_id,