45 lines
1.5 KiB
Markdown
45 lines
1.5 KiB
Markdown
# Orchestrator Usage
|
|
|
|
This service provides robust phase-based sequencing with automatic checkpointing and per-phase retry policy.
|
|
|
|
## Usage (Programmatic)
|
|
|
|
```
|
|
ts
|
|
import { SequentialOrchestrator } from './src/backend/services/SequentialOrchestrator';
|
|
|
|
const orchestrator = new SequentialOrchestrator({
|
|
phases: [
|
|
{ name: 'one', run: async () => { /* logic */ }, retry: 2, backoffMs: 250 },
|
|
{ name: 'two', run: async () => { /* logic */ }},
|
|
// ...more phases
|
|
],
|
|
checkpointPath: 'data/orchestrator-checkpoint.json', // optional, default as shown
|
|
input: {...}, // input passed to each phase
|
|
});
|
|
|
|
await orchestrator.run(); // Runs/resumes from last incomplete phase, checkpointing after each attempt
|
|
```
|
|
|
|
## Features
|
|
- **Sequential phases**: Executes provided phases in-order.
|
|
- **Per-phase retry & backoff**: Configure max attempts and delay for each phase.
|
|
- **Checkpointing**: Persists after every attempt (success/failure/attempt #, timestamp, error message if fail).
|
|
- **Restart-safe**: Can safely resume after crash/restart, picks up at last incomplete phase.
|
|
- **Minimal callable interface**: Import and use from your own services or app code.
|
|
|
|
## Checkpoint Schema
|
|
See `src/backend/services/SequentialOrchestrator.ts` for full type:
|
|
- `currentPhase`: index of next phase to execute
|
|
- `phaseResults[]`: history of all attempts on every phase
|
|
- `inProgress`: true if incomplete (failed phase, retries exhausted)
|
|
|
|
## Testing
|
|
Run:
|
|
|
|
```
|
|
npm test
|
|
```
|
|
|
|
See source: `src/backend/tests/orchestrator.test.ts` for coverage: execution order, retry, checkpoint, resume.
|