37 lines
824 B
Rust
37 lines
824 B
Rust
|
use std::collections::BTreeMap;
|
||
|
|
||
|
use crate::agent::actions::Plan;
|
||
|
|
||
|
#[derive(Clone)]
|
||
|
pub struct ScheduledTasks {}
|
||
|
impl ScheduledTasks {
|
||
|
pub fn new() -> Self {
|
||
|
Self {}
|
||
|
}
|
||
|
|
||
|
pub async fn handle(
|
||
|
&self,
|
||
|
task: &str,
|
||
|
_properties: BTreeMap<String, String>,
|
||
|
) -> anyhow::Result<()> {
|
||
|
// Get plan
|
||
|
let plan = Plan::new();
|
||
|
let tasks = plan.tasks().await?;
|
||
|
|
||
|
// For task
|
||
|
for task in tasks {
|
||
|
// Check idempotency rules
|
||
|
if !task.should_run().await? {
|
||
|
tracing::debug!(task = task.id(), "skipping run");
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
// Run task if not valid
|
||
|
tracing::info!(task = task.id(), "executing task");
|
||
|
task.execute().await?;
|
||
|
}
|
||
|
|
||
|
Ok(())
|
||
|
}
|
||
|
}
|