(
scheduleId: string,
updates: WorkflowScheduleUpdate,
requestId: string,
context: string,
options: { expectedLastQueuedAt?: Date | null } = {}
)
| 132 | } |
| 133 | |
| 134 | async function applyScheduleUpdate( |
| 135 | scheduleId: string, |
| 136 | updates: WorkflowScheduleUpdate, |
| 137 | requestId: string, |
| 138 | context: string, |
| 139 | options: { expectedLastQueuedAt?: Date | null } = {} |
| 140 | ): Promise<boolean> { |
| 141 | try { |
| 142 | const claimGuard = |
| 143 | options.expectedLastQueuedAt === undefined |
| 144 | ? undefined |
| 145 | : options.expectedLastQueuedAt === null |
| 146 | ? isNull(workflowSchedule.lastQueuedAt) |
| 147 | : eq(workflowSchedule.lastQueuedAt, options.expectedLastQueuedAt) |
| 148 | |
| 149 | const updatedRows = await db |
| 150 | .update(workflowSchedule) |
| 151 | .set(updates) |
| 152 | .where( |
| 153 | and(eq(workflowSchedule.id, scheduleId), isNull(workflowSchedule.archivedAt), claimGuard) |
| 154 | ) |
| 155 | .returning({ id: workflowSchedule.id }) |
| 156 | |
| 157 | return updatedRows.length > 0 |
| 158 | } catch (error) { |
| 159 | logger.error(`[${requestId}] ${context}`, error, { cause: describeError(error) }) |
| 160 | throw error |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | export async function releaseScheduleLock( |
| 165 | scheduleId: string, |
no test coverage detected