refactor: reuse resume run store

This commit is contained in:
lda
2026-09-10 05:26:48 +07:00 Verified
parent 422dd57db6
commit 6f8e63eb16
+5 -15
View File
@@ -2,10 +2,12 @@ from __future__ import annotations
import asyncio import asyncio
from dataclasses import asdict from dataclasses import asdict
from datetime import UTC, datetime
from typing import Any, Protocol from typing import Any, Protocol
from wf_artifacts import ( from wf_artifacts import (
DependencyDiagnostic, DependencyDiagnostic,
ResumeAttempt,
RunStore, RunStore,
StoredRunStatus, StoredRunStatus,
WorkflowArtifact, WorkflowArtifact,
@@ -266,7 +268,7 @@ class WorkflowRunApi:
) )
if has_blocking_diagnostics(diagnostics): if has_blocking_diagnostics(diagnostics):
blocked = mark_resume_blocked( blocked = mark_resume_blocked(
store=self._run_store(), store=store,
record=record, record=record,
diagnostics=diagnostics, diagnostics=diagnostics,
) )
@@ -291,20 +293,8 @@ class WorkflowRunApi:
# the ACTIVE marker so recovery fails closed instead of presenting # the ACTIVE marker so recovery fails closed instead of presenting
# the old checkpoint as safe to retry. Every stopped result echoes # the old checkpoint as safe to retry. Every stopped result echoes
# the attempt identity back for matching. # the attempt identity back for matching.
from datetime import UTC as _UTC
from datetime import datetime as _datetime
from wf_artifacts.runs.models import ResumeAttempt
store = self._run_store()
existing_attempt = store.get_resume_attempt(run_id)
if existing_attempt is not None and existing_attempt.state == "ACTIVE":
raise ValueError(
f"workflow run {run_id!r} has an ambiguous active resume attempt; "
"recovery must fail it closed before retry"
)
attempt_id = store.allocate_resume_attempt_id() attempt_id = store.allocate_resume_attempt_id()
now_marker = _datetime.now(_UTC) now_marker = datetime.now(UTC)
store.save_resume_attempt( store.save_resume_attempt(
ResumeAttempt( ResumeAttempt(
run_id=run_id, run_id=run_id,
@@ -335,7 +325,7 @@ class WorkflowRunApi:
run_id=run_id, run_id=run_id,
attempt_id=attempt_id, attempt_id=attempt_id,
) )
cleared_at = _datetime.now(_UTC) cleared_at = datetime.now(UTC)
store.save_resume_attempt( store.save_resume_attempt(
ResumeAttempt( ResumeAttempt(
run_id=run_id, run_id=run_id,