( params: PerformUpdateJobParams )
| 263 | } |
| 264 | |
| 265 | export async function performUpdateJob( |
| 266 | params: PerformUpdateJobParams |
| 267 | ): Promise<PerformScheduleResult> { |
| 268 | try { |
| 269 | const [job] = await db |
| 270 | .select() |
| 271 | .from(workflowSchedule) |
| 272 | .where(activeJobCondition(params.jobId, params.workspaceId)) |
| 273 | .limit(1) |
| 274 | |
| 275 | if (!job) |
| 276 | return { success: false, error: `Job not found: ${params.jobId}`, errorCode: 'not_found' } |
| 277 | |
| 278 | const updates: Partial<typeof workflowSchedule.$inferInsert> = { updatedAt: new Date() } |
| 279 | if (params.title !== undefined) updates.jobTitle = params.title.trim() |
| 280 | if (params.prompt !== undefined) updates.prompt = params.prompt.trim() |
| 281 | if (params.timezone !== undefined) updates.timezone = params.timezone |
| 282 | if (params.status !== undefined) { |
| 283 | if (!['active', 'paused', 'disabled'].includes(params.status)) { |
| 284 | return { |
| 285 | success: false, |
| 286 | error: 'status must be "active" or "paused"', |
| 287 | errorCode: 'validation', |
| 288 | } |
| 289 | } |
| 290 | updates.status = params.status === 'paused' ? 'disabled' : params.status |
| 291 | } |
| 292 | if (params.lifecycle !== undefined) { |
| 293 | if (params.lifecycle !== 'persistent' && params.lifecycle !== 'until_complete') { |
| 294 | return { |
| 295 | success: false, |
| 296 | error: 'lifecycle must be "persistent" or "until_complete"', |
| 297 | errorCode: 'validation', |
| 298 | } |
| 299 | } |
| 300 | updates.lifecycle = params.lifecycle |
| 301 | if (params.lifecycle === 'persistent') updates.maxRuns = null |
| 302 | } |
| 303 | if (params.successCondition !== undefined) updates.successCondition = params.successCondition |
| 304 | if (params.maxRuns !== undefined) updates.maxRuns = params.maxRuns |
| 305 | if (params.contexts !== undefined) updates.contexts = params.contexts |
| 306 | const effectiveStatus = updates.status ?? job.status |
| 307 | |
| 308 | let endsAt: Date | null = job.endsAt |
| 309 | if (params.endsAt !== undefined) { |
| 310 | if (params.endsAt === null) { |
| 311 | endsAt = null |
| 312 | } else { |
| 313 | const parsedEndsAt = new Date(params.endsAt) |
| 314 | if (Number.isNaN(parsedEndsAt.getTime())) { |
| 315 | return { |
| 316 | success: false, |
| 317 | error: `Invalid endsAt value: ${params.endsAt}`, |
| 318 | errorCode: 'validation', |
| 319 | } |
| 320 | } |
| 321 | endsAt = parsedEndsAt |
| 322 | } |
no test coverage detected