Dispatcher & Hooks
Wire workflow execution in Node or Cloudflare via durable hooks.
Workflows execute when durable hooks are processed. Request paths enqueue and notify; the dispatcher is responsible for running the workflow hooks when work is available.
In-process dispatcher (Node)
Use the in-process dispatcher for local development or small deployments:
import { createDurableHooksProcessor } from "@fragno-dev/db/dispatchers/node";
const dispatcher = createDurableHooksProcessor([fragment], {
pollIntervalMs: 2000,
});
dispatcher.startPolling();Cloudflare Durable Object dispatcher
For Cloudflare, use the Durable Object dispatcher package so alarms drive hook processing:
import { createDurableHooksProcessor } from "@fragno-dev/db/dispatchers/cloudflare-do";
import { createMyWorkflowFragment, type MyWorkflowFragment } from "@/fragno/workflows-fragment";
export class WorkflowsDispatcher {
state: DurableObjectState;
fragment: MyWorkflowFragment;
handler: ReturnType<ReturnType<NonNullable<typeof createDurableHooksProcessor>>>;
constructor(state: DurableObjectState, env: Env) {
this.state = state;
this.fragment = createMyWorkflowFragment({ env, state: this.state });
const dispatcher = createDurableHooksProcessor([this.fragment]);
this.handler = dispatcher(state, env);
}
fetch(request: Request) {
return this.fragment.handler(request, {
waitUntil: this.state.waitUntil.bind(this.state),
});
}
alarm() {
return this.handler.alarm?.();
}
}Notes
- Protect dispatcher endpoints or workers with auth and network-level controls.
- Use a durable hook processor/dispatcher to run workflows when enqueued.
- Multiple dispatcher instances can safely poll concurrently.