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

Function restoreScheduleClaim

apps/sim/app/api/schedules/execute/route.ts:242–276  ·  view source on GitHub ↗
(
  scheduleId: string,
  requestId: string,
  currentClaim: Date,
  activeClaim: Date,
  context: string
)

Source from the content-addressed store, hash-verified

240}
241
242async function restoreScheduleClaim(
243 scheduleId: string,
244 requestId: string,
245 currentClaim: Date,
246 activeClaim: Date,
247 context: string
248): Promise<void> {
249 if (currentClaim.getTime() === activeClaim.getTime()) return
250
251 const [restored] = await db
252 .update(workflowSchedule)
253 .set({ lastQueuedAt: activeClaim, updatedAt: new Date() })
254 .where(
255 and(
256 eq(workflowSchedule.id, scheduleId),
257 isNull(workflowSchedule.archivedAt),
258 eq(workflowSchedule.lastQueuedAt, currentClaim)
259 )
260 )
261 .returning({ id: workflowSchedule.id })
262 .catch((error) => {
263 logger.error(`[${requestId}] ${context}`, error)
264 throw error
265 })
266
267 if (!restored) {
268 const error = new Error(`Schedule claim restore did not update schedule ${scheduleId}`)
269 logger.warn(`[${requestId}] ${context}`, {
270 scheduleId,
271 currentClaim: currentClaim.toISOString(),
272 activeClaim: activeClaim.toISOString(),
273 })
274 throw error
275 }
276}
277
278function getStaleScheduleExecutionCutoff(now: Date): Date {
279 return new Date(now.getTime() - STALE_SCHEDULE_CLAIM_MS)

Callers 1

processScheduleItemFunction · 0.85

Calls 4

errorMethod · 0.80
setMethod · 0.65
warnMethod · 0.65
eqFunction · 0.50

Tested by

no test coverage detected