- TaskEngine port + OpenWorkflowEngine ([email protected].1, schema openworkflow): enqueue/signal/cancel/get/list/startWorker/stop - defineTask registry with zod input schema; 9 stub task definitions (§3.1-8) - TaskContext: step.run/sleep/waitForFact, redacting logger, traceId, attemptToken, abortSignal driven by PG cancel flag - signal persists fact to tasks_fact first; waitForFact checks DB before waiting - OutboxRelay: FOR UPDATE SKIP LOCKED, idempotencyKey outbox:<id> - withAttemptToken fencing on tasks_op_ledger (own migration, merged in W2) - tests: kill -9 crash recovery (child worker), cancel, idempotency, concurrent relays, early fact, lease-loss fencing Co-Authored-By: Claude Fable 5.1 <[email protected]>
14 lines
579 B
TypeScript
14 lines
579 B
TypeScript
// 崩溃恢复测试用的 worker 子进程:SCHEMA / OW_SCHEMA 指定测试 schema,HANG_STEP3=1 让第 3 步卡住
|
|
import { connectDb, setupEngine } from "../helpers";
|
|
import { createTestRegistry } from "./tasks";
|
|
|
|
const db = connectDb(process.env.SCHEMA!);
|
|
const engine = await setupEngine(db, { ow: process.env.OW_SCHEMA! }, createTestRegistry(db));
|
|
await engine.startWorker({ versions: ["threeSteps@1"], concurrency: 2 });
|
|
console.log(`worker ready pid=${process.pid}`);
|
|
process.on("SIGTERM", async () => {
|
|
await engine.stop();
|
|
await db.destroy();
|
|
process.exit(0);
|
|
});
|