MCPcopy Index your code
hub / github.com/simstudioai/sim / updateIfLeaseHeld

Function updateIfLeaseHeld

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

* Conditional terminal update scoped to the lease acquired at claim * time. Returns true if the UPDATE affected a row, false if the row's * lease was revoked (reaped, reclaimed by another worker). Callers * treat `false` as a "lease lost" signal and skip without retrying — * the newer owner is r

(
  event: typeof outboxEvent.$inferSelect,
  patch: {
    status: 'completed' | 'pending' | 'dead_letter'
    attempts?: number
    lastError?: string | null
    availableAt?: Date
    lockedAt: Date | null
    processedAt?: Date | null
  }
)

Source from the content-addressed store, hash-verified

555 * the newer owner is responsible for the row now.
556 */
557async function updateIfLeaseHeld(
558 event: typeof outboxEvent.$inferSelect,
559 patch: {
560 status: 'completed' | 'pending' | 'dead_letter'
561 attempts?: number
562 lastError?: string | null
563 availableAt?: Date
564 lockedAt: Date | null
565 processedAt?: Date | null
566 }
567): Promise<boolean> {
568 const whereClauses = [eq(outboxEvent.id, event.id), eq(outboxEvent.status, 'processing')]
569 if (event.lockedAt) {
570 whereClauses.push(eq(outboxEvent.lockedAt, event.lockedAt))
571 }
572
573 const result = await db
574 .update(outboxEvent)
575 .set(patch)
576 .where(and(...whereClauses))
577 .returning({ id: outboxEvent.id })
578
579 return result.length > 0
580}

Callers 3

runHandlerFunction · 0.85
recordTimedOutAttemptFunction · 0.85
scheduleRetryFunction · 0.85

Calls 3

setMethod · 0.65
eqFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected