( scheduleId: string, requestId: string, currentClaim: Date, activeClaim: Date, context: string )
| 240 | } |
| 241 | |
| 242 | async 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 | |
| 278 | function getStaleScheduleExecutionCutoff(now: Date): Date { |
| 279 | return new Date(now.getTime() - STALE_SCHEDULE_CLAIM_MS) |
no test coverage detected