(targetId: string, workspaceId: string, enabled: boolean)
| 276 | * Caller is responsible for notifying ScheduleBeat after this returns. |
| 277 | */ |
| 278 | const toggleScheduleEnabled = async (targetId: string, workspaceId: string, enabled: boolean): Promise<ScheduleRecord> => { |
| 279 | try { |
| 280 | const appServer = getRunningExpressApp() |
| 281 | const repo = appServer.AppDataSource.getRepository(ScheduleRecord) |
| 282 | const record = await repo.findOne({ |
| 283 | where: { targetId, triggerType: ScheduleTriggerType.AGENTFLOW, workspaceId } |
| 284 | }) |
| 285 | if (!record) { |
| 286 | throw new InternalFlowiseError(StatusCodes.NOT_FOUND, 'No schedule record found for this flow') |
| 287 | } |
| 288 | |
| 289 | if (enabled) { |
| 290 | const status = await getScheduleStatus(targetId, workspaceId) |
| 291 | if (!status.canEnable) { |
| 292 | throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, status.reason || 'Cannot enable schedule: invalid configuration') |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | record.enabled = enabled |
| 297 | const saved = await repo.save(record) |
| 298 | logger.debug(`[ScheduleService]: Schedule ${record.id} toggled to ${enabled ? 'enabled' : 'disabled'}`) |
| 299 | return saved |
| 300 | } catch (error) { |
| 301 | if (error instanceof InternalFlowiseError) throw error |
| 302 | throw new InternalFlowiseError( |
| 303 | StatusCodes.INTERNAL_SERVER_ERROR, |
| 304 | `Error: scheduleService.toggleScheduleEnabled - ${getErrorMessage(error)}` |
| 305 | ) |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | // ─── Log functions ───────────────────────────────────────────────────────────── |
| 310 |
nothing calls this directly
no test coverage detected