Skip to main content

apps/gateway/src/workers/outbox-dispatcher.ts

Metadata

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");