All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
39 lines
873 B
Rust
39 lines
873 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<()> {
|
|
tracing::info!("scheduling: {}", task);
|
|
|
|
// 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(())
|
|
}
|
|
}
|