MCPcopy
hub / github.com/simstudioai/sim / reapStuckProcessingRows

Function reapStuckProcessingRows

apps/sim/lib/core/outbox/service.ts:248–263  ·  view source on GitHub ↗

* Reaper: move `processing` rows whose worker died (stale `lockedAt`) * back to `pending` so another worker can pick them up. Without this, * a SIGKILL between claim and result-write would permanently strand * the row in `processing`.

()

Source from the content-addressed store, hash-verified

246 * the row in `processing`.
247 */
248async function reapStuckProcessingRows(): Promise<number> {
249 const stuckBefore = new Date(Date.now() - STUCK_PROCESSING_THRESHOLD_MS)
250 const result = await db
251 .update(outboxEvent)
252 .set({ status: 'pending', lockedAt: null })
253 .where(and(eq(outboxEvent.status, 'processing'), lte(outboxEvent.lockedAt, stuckBefore)))
254 .returning({ id: outboxEvent.id })
255
256 if (result.length > 0) {
257 logger.warn('Reaped stuck outbox processing rows', {
258 count: result.length,
259 thresholdMs: STUCK_PROCESSING_THRESHOLD_MS,
260 })
261 }
262 return result.length
263}
264
265/**
266 * Phase 1: claim a batch of due pending events.

Callers 1

processOutboxEventsFunction · 0.85

Calls 3

setMethod · 0.65
warnMethod · 0.65
eqFunction · 0.50

Tested by

no test coverage detected