MCPcopy
hub / github.com/holaboss-ai/holaOS / RuntimeQueueWorker

Class RuntimeQueueWorker

runtime/api-server/src/queue-worker.ts:112–755  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110}
111
112export class RuntimeQueueWorker implements QueueWorkerLike {
113 readonly #store: RuntimeStateStore;
114 readonly #logger: RuntimeQueueWorkerOptions["logger"];
115 readonly #executeClaimedInput: (record: SessionInputRecord, options?: { signal?: AbortSignal }) => Promise<void>;
116 readonly #captureRuntimeException: typeof captureRuntimeException;
117 readonly #claimedBy: string;
118 readonly #leaseSeconds: number;
119 readonly #pollIntervalMs: number;
120 readonly #maxConcurrency: number;
121 readonly #claimStaleHeartbeatMs: number;
122 #stopped = false;
123 #task: Promise<void> | null = null;
124 #wakeResolver: (() => void) | null = null;
125 #activeRuns = new Map<
126 string,
127 {
128 controller: AbortController;
129 record: SessionInputRecord;
130 promise: Promise<void>;
131 }
132 >();
133
134 constructor(options: RuntimeQueueWorkerOptions) {
135 this.#store = options.store;
136 this.#logger = options.logger;
137 this.#claimedBy = options.claimedBy ?? DEFAULT_CLAIMED_BY;
138 this.#captureRuntimeException =
139 options.captureRuntimeException ?? captureRuntimeException;
140 this.#executeClaimedInput =
141 options.executeClaimedInput ??
142 ((record, executionOptions) =>
143 processClaimedInput({
144 store: this.#store,
145 record,
146 claimedBy: this.#claimedBy,
147 leaseSeconds: this.#leaseSeconds,
148 memoryService: options.memoryService ?? null,
149 wakeDurableMemoryWorker: options.wakeDurableMemoryWorker ?? null,
150 abortSignal: executionOptions?.signal,
151 }));
152 this.#leaseSeconds = options.leaseSeconds ?? DEFAULT_LEASE_SECONDS;
153 this.#pollIntervalMs = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
154 this.#maxConcurrency = options.maxConcurrency ?? queueWorkerMaxConcurrency();
155 this.#claimStaleHeartbeatMs =
156 options.claimStaleHeartbeatMs ?? queueWorkerClaimStaleHeartbeatMs();
157 }
158
159 async start(): Promise<void> {
160 if (this.#task) {
161 return;
162 }
163 this.#stopped = false;
164 this.#task = this.#runLoop();
165 }
166
167 wake(): void {
168 const resolve = this.#wakeResolver;
169 this.#wakeResolver = null;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected