Flow Scheduling System
Relevant source files
The following files were used as context for generating this wiki page:
The Flow Scheduling System is a core component of the SweepBot NLP Automation Engine, responsible for managing the lifecycle of scheduled automation scripts. It enables users to execute complex casino routines at specific times or intervals using standard cron syntax. The system integrates natural language interpretation with high-precision scheduling, ensuring that tasks such as daily bonus collection or recurring play strategies are executed reliably according to the user's specified timezone.
Sources: packages/flows/README.md, AGENTS.md
System Architecture
The scheduling system acts as the bridge between the NLP Flow Engine and the Flow Executor. When a user provides a natural language command (e.g., "Every day at 3 PM"), the interpreter extracts scheduling entities and the scheduler registers a corresponding cron job.
Component Relationship
The following diagram illustrates how the FlowScheduler interacts with other internal components to activate and run flows.
The scheduler maintains an internal registry of active jobs and utilizes node-cron for precise timing.
Sources: packages/flows/README.md, packages/flows/src/scheduler/scheduler.ts
Core Scheduling Logic
The system is encapsulated within the FlowScheduler class. Its primary responsibility is managing FlowDefinition objects that contain a FlowTrigger of type scheduled.
Scheduling Methods
| Method | Description |
|---|---|
activateFlow | Registers a new cron job for a flow based on its cron expression and timezone. |
pauseFlow | Stops a running job and removes it from the active registry. |
resumeFlow | Re-registers a previously paused flow into the active job list. |
reactivateAllFlows | Bulk reactivates flows, used during system startup to recover active schedules. |
Sources: packages/flows/src/scheduler/scheduler.ts, packages/flows/README.md
Scheduled Triggers
A scheduled trigger is defined by two primary properties:
- Cron Expression: A standard string format (e.g.,
0 9 * * *for daily at 9 AM). - Timezone: A string identifier (e.g.,
America/New_York) to ensure local time accuracy.
Sources: packages/flows/src/interpreter/interpreter.ts:182-192, packages/flows/src/tests/scheduler.test.ts:25-30
Integration with NLP Interpreter
The FlowInterpreter is responsible for generating the scheduling data that the FlowScheduler consumes. During the 4-pass interpretation pipeline, the EntityRecognizer identifies temporal phrases and converts them into cron-compatible triggers.
Trigger Extraction
The interpreter searches for schedules entities within the EntityMap. If found, it populates the FlowTrigger metadata:
- Manual: If no temporal data is provided.
- Scheduled: If phrases like "daily", "every day at X", or "every hour" are detected.
Sources: packages/flows/src/interpreter/interpreter.ts:182-192, packages/flows/src/interpreter/interpreter.ts:245-252
/**
* Extract the trigger from entities
*/
private extractTrigger(entities: EntityMap): FlowTrigger | null {
if (entities.schedules.length > 0) {
const schedule = entities.schedules[0]!
return {
type: 'scheduled',
cron: schedule.cron,
timezone: schedule.timezone,
}
}
return null
}
Sources: packages/flows/src/interpreter/interpreter.ts:182-192
Operational Performance and Recovery
The scheduler is designed for high efficiency and reliability. It features O(1) activation and lookup times. For system resilience, the reactivateAllFlows method allows the engine to recover all active flows from the database upon application restart, ensuring no scheduled tasks are missed due to system downtime.
Sources: packages/flows/README.md, packages/flows/src/scheduler/scheduler.ts
Summary
The Flow Scheduling System provides the temporal execution backbone for SweepBot. By combining node-cron precision with flexible timezone support and an NLP-driven trigger extraction process, it allows users to automate casino routines with high natural language flexibility and operational reliability.
Sources: packages/flows/README.md, AGENTS.md