pub struct CronScheduler { /* private fields */ }Expand description
The cron scheduler for time-based autonomous agent execution.
Allows scheduling agents to run on cron-like schedules without user intervention.
Supports 5-field (Linux cron) and 6-7 field expressions via the cron crate.
Implementations§
Source§impl CronScheduler
impl CronScheduler
Sourcepub fn new(state_store: Arc<StateStore>, tick_interval_secs: u64) -> Self
pub fn new(state_store: Arc<StateStore>, tick_interval_secs: u64) -> Self
Create a new CronScheduler.
§Arguments
state_store- State store for persisting job definitionstick_interval_secs- How often to check for due jobs (in seconds)
Sourcepub fn set_max_concurrent_jobs(&mut self, max: usize)
pub fn set_max_concurrent_jobs(&mut self, max: usize)
Set the maximum concurrent cron job executions.
Sourcepub fn set_job_timeout_secs(&mut self, secs: u64)
pub fn set_job_timeout_secs(&mut self, secs: u64)
Set the timeout for individual cron job execution in seconds.
Sourcepub fn set_git_layer(&mut self, gl: Arc<GitLayer>)
pub fn set_git_layer(&mut self, gl: Arc<GitLayer>)
Set the git layer for version-controlled saves.
Sourcepub async fn add_job(&self, job: CronJob) -> Result<Uuid>
pub async fn add_job(&self, job: CronJob) -> Result<Uuid>
Add a job. Parses schedule, computes next_run, stores.
Sourcepub async fn remove_job(&self, id: Uuid) -> Result<()>
pub async fn remove_job(&self, id: Uuid) -> Result<()>
Remove a job by ID.
Sourcepub async fn update_job(&self, id: Uuid, update: CronJobUpdate) -> Result<()>
pub async fn update_job(&self, id: Uuid, update: CronJobUpdate) -> Result<()>
Update a job’s fields (enabled, schedule, goal, etc).
Sourcepub async fn toggle_job(&self, id: Uuid, enabled: bool) -> Result<()>
pub async fn toggle_job(&self, id: Uuid, enabled: bool) -> Result<()>
Toggle a job enabled/disabled.
Sourcepub fn is_running(&self, id: Uuid) -> bool
pub fn is_running(&self, id: Uuid) -> bool
Check if a job is currently running.
Sourcepub fn trigger_job(&self, id: Uuid) -> Result<CronJob>
pub fn trigger_job(&self, id: Uuid) -> Result<CronJob>
Trigger a job immediately (manual execution, ignores schedule).
Returns the job goal as a string for the caller to execute.
The caller is responsible for calling mark_job_completed after execution.
Sourcepub async fn mark_job_completed(&self, id: Uuid, success: bool, summary: String)
pub async fn mark_job_completed(&self, id: Uuid, success: bool, summary: String)
Mark a job execution as completed.
Sourcepub async fn start<F, Fut>(self: Arc<Self>, executor: F)
pub async fn start<F, Fut>(self: Arc<Self>, executor: F)
Start the main loop. Must be called on an Arc<Self>.
§Arguments
executor- Async closure(Uuid, String) -> Futwhere args are(job_id, goal), returning(success, summary).
§Example
use std::sync::Arc;
use oxios_kernel::state_store::StateStore;
use oxios_kernel::cron::CronScheduler;
let state_store = Arc::new(StateStore::new("/tmp/state".into()).unwrap());
let scheduler = Arc::new(CronScheduler::new(state_store, 60));
scheduler.clone().start(|id, goal| async move {
// execute the agent...
(true, "Done".to_string())
}).await;Sourcepub async fn restore_jobs(&self)
pub async fn restore_jobs(&self)
Restore jobs from disk on startup.
Sourcepub async fn load_from_config(&self, config: &CronConfig)
pub async fn load_from_config(&self, config: &CronConfig)
Load jobs defined in config (called during startup). Config-defined jobs are only added if they don’t already exist (API wins on conflict).