All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
47 lines
1.0 KiB
Rust
47 lines
1.0 KiB
Rust
use std::collections::BTreeMap;
|
|
|
|
use crate::agent::{
|
|
actions::Plan,
|
|
plugins::PluginStore,
|
|
task::{ConcreteTask, IntoTask},
|
|
};
|
|
|
|
#[derive(Clone)]
|
|
pub struct ScheduledTasks {
|
|
store: PluginStore,
|
|
}
|
|
impl ScheduledTasks {
|
|
pub fn new(store: PluginStore) -> Self {
|
|
Self { store }
|
|
}
|
|
|
|
pub async fn handle(
|
|
&self,
|
|
task: &str,
|
|
_properties: BTreeMap<String, String>,
|
|
) -> anyhow::Result<()> {
|
|
tracing::info!("scheduling: {}", task);
|
|
|
|
let plan = Plan::new(self.store.clone());
|
|
let tasks: Vec<ConcreteTask> = plan
|
|
.tasks()
|
|
.await?
|
|
.into_iter()
|
|
.map(|i| i.into_task())
|
|
.collect();
|
|
|
|
for task in tasks {
|
|
let id = task.id().await?;
|
|
if !task.should_run().await? {
|
|
tracing::debug!(task = id, "skipping run");
|
|
continue;
|
|
}
|
|
|
|
tracing::info!(task = id, "executing task");
|
|
task.execute().await?;
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
}
|