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

Function retryScheduleAfterInfraFailure

apps/sim/background/schedule-execution.ts:189–261  ·  view source on GitHub ↗
({
  payload,
  requestId,
  claimedAt,
  error,
  message,
  cause,
}: {
  payload: ScheduleExecutionPayload
  requestId: string
  claimedAt: Date | null
  error?: unknown
  message?: string
  cause?: Record<string, unknown>
})

Source from the content-addressed store, hash-verified

187}
188
189async function retryScheduleAfterInfraFailure({
190 payload,
191 requestId,
192 claimedAt,
193 error,
194 message,
195 cause,
196}: {
197 payload: ScheduleExecutionPayload
198 requestId: string
199 claimedAt: Date | null
200 error?: unknown
201 message?: string
202 cause?: Record<string, unknown>
203}) {
204 const now = new Date()
205 const retryAttempt = (payload.infraRetryCount || 0) + 1
206 if (retryAttempt > SCHEDULE_INFRA_RETRY_MAX_ATTEMPTS) {
207 logger.error(`[${requestId}] Retryable infrastructure failures exhausted for schedule`, {
208 scheduleId: payload.scheduleId,
209 workflowId: payload.workflowId,
210 retryAttempt,
211 maxAttempts: SCHEDULE_INFRA_RETRY_MAX_ATTEMPTS,
212 cause: cause ?? describeRetryableInfrastructureError(error),
213 })
214
215 const nextRunAt = await determineNextRunAfterError(payload, now, requestId)
216 await applyScheduleUpdate(
217 payload.scheduleId,
218 buildScheduleFailureUpdate(now, nextRunAt),
219 requestId,
220 `Error updating schedule ${payload.scheduleId} after exhausted infrastructure retries`,
221 { expectedLastQueuedAt: claimedAt }
222 )
223 return
224 }
225
226 const retryDelayMs = Math.min(
227 SCHEDULE_INFRA_RETRY_MAX_MS,
228 Math.round(
229 backoffWithJitter(retryAttempt, null, {
230 baseMs: SCHEDULE_INFRA_RETRY_BASE_MS,
231 maxMs: SCHEDULE_INFRA_RETRY_MAX_MS,
232 })
233 )
234 )
235 const nextRetryAt = new Date(now.getTime() + retryDelayMs)
236 const failureCause = cause ?? describeRetryableInfrastructureError(error)
237 const errorMessage = message ?? (error ? toError(error).message : undefined)
238
239 logger.warn(`[${requestId}] Retryable infrastructure failure during scheduled setup`, {
240 scheduleId: payload.scheduleId,
241 workflowId: payload.workflowId,
242 retryAttempt,
243 error: errorMessage,
244 retryDelayMs,
245 nextRetryAt: nextRetryAt.toISOString(),
246 cause: failureCause,

Callers 1

executeScheduleJobFunction · 0.85

Calls 8

backoffWithJitterFunction · 0.90
toErrorFunction · 0.90
applyScheduleUpdateFunction · 0.85
errorMethod · 0.80
warnMethod · 0.65

Tested by

no test coverage detected