All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
43 lines
931 B
Rust
43 lines
931 B
Rust
use std::collections::BTreeMap;
|
|
|
|
use crate::agent::{
|
|
actions::Plan,
|
|
task::{ConcreteTask, IntoTask},
|
|
};
|
|
|
|
#[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);
|
|
|
|
let plan = Plan::new();
|
|
let tasks: Vec<ConcreteTask> = plan
|
|
.tasks()
|
|
.await?
|
|
.into_iter()
|
|
.map(|i| i.into_task())
|
|
.collect();
|
|
|
|
for task in tasks {
|
|
if !task.should_run().await? {
|
|
tracing::debug!(task = task.id(), "skipping run");
|
|
continue;
|
|
}
|
|
|
|
tracing::info!(task = task.id(), "executing task");
|
|
task.execute().await?;
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
}
|