Package com.tnsai.reliability
Class DefaultResumableRun<S>
java.lang.Object
com.tnsai.reliability.DefaultResumableRun<S>
- Type Parameters:
S- state type threaded through the step list
- All Implemented Interfaces:
ResumableRun<S,S>
Default
ResumableRun implementation (TNS-299). Drives a fixed
list of DefaultResumableRun.Steps through CheckpointStore,
IdempotencyStore (TNS-224), and ProgressSink.
Step model
Each step is aUnaryOperator over a typed state S.
The run starts with an input state, threads it through the step list,
and returns the terminal state. Steps marked
DefaultResumableRun.Step.sideEffecting consult the idempotency store before
running so a retry never double-executes a write — the previous
stored result is replayed instead.
Crash recovery
After every successful step the orchestrator persists aCheckpoint carrying the post-step state. If the JVM dies
mid-run, calling resume(String) with the same runId
loads the latest checkpoint and continues from the next step.
Cost ceiling
DefaultResumableRun.Builder.costMonitor is optional. When provided AND
RunConfig.costCeilingUSD is set, the orchestrator queries it
before every step; if cumulative spend has reached the ceiling, the
run aborts with AbortReason.BUDGET_EXHAUSTED after saving a
final checkpoint (so the consumer can resume on a higher ceiling).
Concurrency
One instance handles many concurrent runs.execute(S, com.tnsai.reliability.RunConfig) /
resume(java.lang.String) / abort(java.lang.String, com.tnsai.reliability.AbortReason) are safe to call concurrently from
different threads, each owning its own run id.- Since:
- 0.10.0 (TNS-299)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic interfaceOptional cost-governance hook.static interfaceEncodes / decodes the run's state to bytes for checkpoint persistence.static final recordOne unit of work in the run. -
Method Summary
Modifier and TypeMethodDescriptionvoidabort(String runId, AbortReason reason) Stop a run that's currently in flight.static <S> DefaultResumableRun.Builder<S> builder()Start a new run.Pick up a paused run from its latest checkpoint.
-
Method Details
-
builder
-
execute
Description copied from interface:ResumableRunStart a new run. The orchestrator mints a fresh run id, walks the step list, and returns a terminalOutcome.- Specified by:
executein interfaceResumableRun<S,S> - Parameters:
input- initial input handed to the first stepconfig- execution-time policies; bounds duration / retries / cost / progress timeout- Returns:
- one of the four
Outcomevariants — never null
-
resume
Description copied from interface:ResumableRunPick up a paused run from its latest checkpoint. The orchestrator loads the checkpoint viaCheckpointStore.latest(java.lang.String), restores step state, and continues from the next step.If no checkpoint exists for
runId, the implementation returnsOutcome.Failedwith a clear "no such run" message rather than starting a fresh one — confusing one for the other was the bug pattern this primitive is supposed to prevent.- Specified by:
resumein interfaceResumableRun<S,S>
-
abort
Description copied from interface:ResumableRunStop a run that's currently in flight. The orchestrator transitions toOutcome.Abortedat the next step boundary; already-running step bodies are not interrupted, so abort is cooperative — designed for "graceful shutdown by the next safe point" rather than mid-call cancellation.Calling
aborton a run id that isn't in flight is a no-op (already terminated runs ignore the request).- Specified by:
abortin interfaceResumableRun<S,S>
-