MCPcopy Create free account
hub / github.com/FlowiseAI/Flowise / toggleScheduleEnabled

Function toggleScheduleEnabled

packages/server/src/services/schedule/index.ts:278–307  ·  view source on GitHub ↗
(targetId: string, workspaceId: string, enabled: boolean)

Source from the content-addressed store, hash-verified

276 * Caller is responsible for notifying ScheduleBeat after this returns.
277 */
278const 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

Callers

nothing calls this directly

Calls 3

getRunningExpressAppFunction · 0.90
getErrorMessageFunction · 0.90
getScheduleStatusFunction · 0.70

Tested by

no test coverage detected