Workflow Schedule Template
The Workflow Schedule template demonstrates how BindAI represents and tracks workflows that are intended to execute at specific times or recurring intervals. AWorkflowSchedule stores the workflow identifier, the next scheduled execution time, an optional recurring interval, and whether the schedule is enabled.
The WorkflowScheduler maintains registered schedules and identifies which schedules are currently due.
Purpose
This template demonstrates how to:- create a workflow schedule
- register schedules with a scheduler
- determine which schedules are due
- configure recurring execution intervals
- enable or disable schedules
- advance recurring schedules after execution
Scheduling Architecture
The scheduling components are responsible for determining when a workflow should run.Workflow Schedule
AWorkflowSchedule describes one scheduled workflow.
The current implementation contains four fields:
Registering a Schedule
Schedules are registered withWorkflowScheduler.
Checking Due Schedules
The scheduler provides thedue() method to identify schedules whose execution time has arrived.
Conceptually:
- enabled, and
- whose
next_runis at or before the current time
Due Schedule Example
Suppose the scheduler contains three schedules:10:30:
Enabled Schedules
Only enabled schedules are considered bydue().
next_run has arrived.
Disabled Schedules
A disabled schedule remains registered but is ignored when checking for due schedules.next_run is in the past, due() does not return it.
This allows applications to temporarily disable scheduled workflows without removing their schedule.
One-Time Schedule
A schedule without an interval can represent a one-time execution.reschedule() does not move its next_run because no recurring interval is configured.
The application can therefore treat the schedule as a one-time schedule.
Recurring Schedule
A recurring schedule specifiesinterval_seconds.
Rescheduling
Thereschedule() method updates recurring schedules.
Conceptually:
interval_seconds is not configured, the schedule is not advanced.
Scheduler Lifecycle
A typical application-level scheduling cycle looks like this:WorkflowScheduler provides the registration, due-checking, and rescheduling portions of this lifecycle.
The surrounding application is responsible for deciding how and when to call these methods and how to execute the returned workflows.
Scheduler Does Not Execute Workflows
The scheduler itself does not invoke a workflow executor. Its responsibility is to identify schedules that are ready.Scheduler vs Workflow Executor
The scheduler and executor have different responsibilities.
The scheduler answers when should this workflow run?
The executor answers how should this workflow execute?
Scheduler vs Loop
Scheduling and loops both support repeated behavior, but at different levels.
A scheduler controls when a workflow starts.
A loop controls how a running workflow repeats.
Example: Hourly Workflow
An application may register an hourly workflow:Multiple Schedules
A single scheduler can contain multiple workflows.due() evaluates all registered schedules and returns the enabled schedules whose next_run has arrived.
Current Time Handling
The current implementation determines due schedules using:next_run against the UTC-based current time returned by datetime.utcnow().
Applications should ensure that the timestamps supplied to WorkflowSchedule are consistent with the time basis expected by the scheduler.
Timezone conversion and user-facing local scheduling are application-level concerns and are not currently implemented by WorkflowScheduler.
Recurring Execution
Recurring schedules are represented using an interval rather than a separate recurrence rule. For example:next_run.
Typical Use Cases
The scheduling mechanism can support workflows such as:- periodic reports
- recurring data synchronization
- scheduled document processing
- periodic knowledge refreshes
- recurring maintenance
- automated backups
- monitoring workflows
- periodic AI processing
Schedule State
A schedule has a small and explicit state model:Best Practices
- Use a consistent time basis for
next_run. - Keep recurring intervals explicit.
- Disable schedules that should temporarily stop running.
- Reschedule recurring schedules after processing them.
- Keep scheduling separate from workflow execution.
- Avoid registering duplicate schedules unintentionally.
- Monitor overdue schedules in the surrounding application.
- Ensure scheduled workflows can safely execute more than once when using recurring schedules.
Related Templates
The Schedule template works well alongside:- Workflow Retry
- Workflow Timeout
- Workflow Parallel
- Workflow Human
Summary
The Workflow Schedule template demonstrates how BindAI represents and manages time-based workflow execution.WorkflowSchedule stores the workflow identifier, next execution time, optional recurrence interval, and enabled state.
WorkflowScheduler provides three core operations:
