feat: add common queue
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
36
crates/churn/src/agent/handlers/scheduled_tasks.rs
Normal file
36
crates/churn/src/agent/handlers/scheduled_tasks.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
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(())
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user