apps/gateway/src/workers/outbox-dispatcher.ts
Metadata
- Purpose: Background worker process for queued asynchronous operations.
- Domain:
applications - Language:
ts - Bytes: 2112
- Lines: 76
- Content hash (short):
ce29a429 - Source (start): apps/gateway/src/workers/outbox-dispatcher.ts:1
- Source (end): apps/gateway/src/workers/outbox-dispatcher.ts:76
Indexed Symbols
sleep(line 7, function) - Implements sleep for background job processing.processEvent(line 16, function) - Implements process event for background job processing.run(line 44, function) - Implements run for background job processing.
Markdown Headings (if applicable)
No markdown headings detected.
Source Preview
import { enqueueAgentExecution } from "../services/agentfield-client.js";
import { markOutboxEventStatus, reservePendingOutboxEvents } from "../services/event-pipeline.js";
import { env } from "../config/env.js";
import { pruneExpiredIdempotencyRecords } from "../services/idempotency-repository.js";
import { heartbeatWorker } from "../services/worker-runtime-repository.js";
function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
type OutboxPayload = {
agent: string;
reasoner: string;
};
async function processEvent(event: {
id: string;
workspaceId: string;
topic: string;
correlationId: string;
payload: unknown;
}) {
const parsedPayload = (event.payload ?? {}) as Partial<OutboxPayload>;
if (!parsedPayload.agent || !parsedPayload.reasoner) {
await markOutboxEventStatus(event.id, "failed");