Runnable end-to-end demos for @razroo/parallel-mcp. Each script runs
straight from source with tsx.
Creates a single run, enqueues a batch of fetch tasks with retry policy,
spins up three concurrent runWorker loops against an in-memory SQLite
store, and prints the onEvent observability stream as tasks flow through
the orchestrator to a terminal run state.
npm run example:fan-outExpected output is a stream of task.enqueued / task.claimed /
task.running / task.completed events from multiple workers, followed by
a final run-status transition and a per-task summary. About 20% of tasks
will deliberately fail on the first attempt to exercise the retry +
not_before paths.
Demonstrates the retry policy and the pause / resume path:
- A
buildtask that fails transiently twice (exponential backoff onretry.delayMs) before succeeding on the third attempt. - A
deploytask that depends onbuild, which pauses itself inwaiting_inputuntil the driver script callsresumeTask. - Final event log shows every state transition end to end.
npm run example:retry-and-resumeGood starting point if you're wiring a human-in-the-loop step or any flow that sits idle waiting for an external signal (approval, webhook, etc.).
A realistic multi-worker setup in one process, showing the pattern you'd use across separate processes as well:
- Shared SQLite file (durable, not
:memory:) so every worker sees the same state. - Eight workers: four restricted to
kinds: ['image'], four that accept any kind. - Dedicated
scheduleExpireLeasessweeper so the workers can passexpireLeasesOnPoll: falseand stay on the hot path. - Single
AbortControllerwired toSIGINT/SIGTERM, propagated to every worker and the sweeper for clean shutdown.
npm run example:multi-workerPrints a per-worker completion tally at the end so you can see how work distributes across workers. Across runs the numbers will vary — that's the point.
End-to-end demo of the 0.4.0 async surface — AsyncParallelMcpOrchestrator
MemoryParallelMcpStore+ a hand-rolled async worker loop + the dead-letter queue.
- Builds an in-memory async store (no Postgres required). Swap in
PostgresParallelMcpStorefor the durable path. - Enqueues three tasks: two happy tasks plus a poison task that simulates a worker crash (claim → stop responding → lease expires).
- Runs two async worker coroutines that opportunistically call
expireLeases()each poll. After the poison task exhaustsmaxAttemptsvia repeated lease expiries, it is parked in the DLQ. - Pulls
listDeadTasks, prints the triage summary, and revives the poison task withrequeueDeadTask({ reason: 'operator replay ...' })— which emitstask.requeued_from_dlq. The replayed task dies again (still poison) to show the DLQ cycle is re-entrant.
npm run example:async-dlq-triageNote: runWorker is currently sync-only. Async callers drive
claimNextTask / markTaskRunning / completeTask / failTask
directly until a first-class runAsyncWorker ships. This example is
the reference for that pattern.