Class SchedulerService
java.lang.Object
ai.nervemind.app.service.SchedulerService
Service for scheduling workflow executions.
Uses virtual threads for efficient handling of many scheduled workflows.
-
Constructor Summary
ConstructorsConstructorDescriptionSchedulerService(WorkflowService workflowService, ExecutionService executionService) Creates a new SchedulerService with the given dependencies. -
Method Summary
Modifier and TypeMethodDescriptionvoidcancelSchedule(Long workflowId) Cancel a scheduled workflow.intGet count of active scheduled workflows.voidInitialize the scheduler by loading and scheduling all active workflows.voidrescheduleWorkflow(Long workflowId) Reschedule a workflow (call when workflow is updated).voidscheduleWorkflow(ai.nervemind.common.dto.WorkflowDTO workflow) Schedule a workflow for execution based on its cron expression.voidshutdown()Shutdown the scheduler and cancel all scheduled tasks.
-
Constructor Details
-
SchedulerService
Creates a new SchedulerService with the given dependencies.- Parameters:
workflowService- the workflow service for managing workflowsexecutionService- the execution service for running workflows
-
-
Method Details
-
initialize
@PostConstruct public void initialize()Initialize the scheduler by loading and scheduling all active workflows. -
shutdown
@PreDestroy public void shutdown()Shutdown the scheduler and cancel all scheduled tasks. -
scheduleWorkflow
public void scheduleWorkflow(ai.nervemind.common.dto.WorkflowDTO workflow) Schedule a workflow for execution based on its cron expression.- Parameters:
workflow- the workflow to schedule
-
cancelSchedule
Cancel a scheduled workflow.- Parameters:
workflowId- the ID of the workflow to cancel
-
rescheduleWorkflow
Reschedule a workflow (call when workflow is updated).- Parameters:
workflowId- the ID of the workflow to reschedule
-
getActiveScheduleCount
public int getActiveScheduleCount()Get count of active scheduled workflows.- Returns:
- the number of currently scheduled workflows
-