From 03e23c7d9d3f6ae0f4fc2f9acab2b038290d8ffb Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sat, 4 Jan 2025 01:52:05 +0100 Subject: [PATCH] feat: enable checking if it should actually run Signed-off-by: kjuulh --- Cargo.lock | 15 +++++++++++++++ crates/churn/Cargo.toml | 1 + crates/churn/src/agent/plugins.rs | 16 +++++++++++++--- crates/churn/src/cli.rs | 7 +++++++ 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b18d4ca..105bcd8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -382,6 +382,7 @@ dependencies = [ "futures", "nodrift", "notmad", + "petname", "prost", "prost-types", "reqwest", @@ -1781,6 +1782,20 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +[[package]] +name = "petname" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cd31dcfdbbd7431a807ef4df6edd6473228e94d5c805e8cf671227a21bad068" +dependencies = [ + "anyhow", + "clap", + "itertools", + "proc-macro2", + "quote", + "rand", +] + [[package]] name = "pin-project" version = "1.1.7" diff --git a/crates/churn/Cargo.toml b/crates/churn/Cargo.toml index e9533c8..71888be 100644 --- a/crates/churn/Cargo.toml +++ b/crates/churn/Cargo.toml @@ -37,3 +37,4 @@ reqwest = { version = "0.12.9", default-features = false, features = [ serde_json = "1.0.133" wasmtime = "28.0.0" wasmtime-wasi = "28.0.0" +petname = "2.0.2" diff --git a/crates/churn/src/agent/plugins.rs b/crates/churn/src/agent/plugins.rs index 5951f03..6a75f7b 100644 --- a/crates/churn/src/agent/plugins.rs +++ b/crates/churn/src/agent/plugins.rs @@ -124,11 +124,21 @@ impl InnerPluginStore { pub async fn execute(&mut self, plugin: &str) -> anyhow::Result<()> { let plugin = self.ensure_plugin(plugin).await?; - plugin + if plugin .interface0 - .call_execute(&mut self.store) + .call_should_run(&mut self.store) .await - .context("Failed to call add function") + .context("Failed to call should run")? + { + tracing::info!("job was marked as required to run"); + return plugin + .interface0 + .call_execute(&mut self.store) + .await + .context("Failed to call add function"); + } + + Ok(()) } async fn ensure_plugin(&mut self, plugin: &str) -> anyhow::Result { diff --git a/crates/churn/src/cli.rs b/crates/churn/src/cli.rs index 0b98d19..4137b22 100644 --- a/crates/churn/src/cli.rs +++ b/crates/churn/src/cli.rs @@ -31,6 +31,13 @@ pub async fn execute() -> anyhow::Result<()> { setup_labels.insert(k, v); } + if !setup_labels.contains_key("node_name") { + setup_labels.insert( + "node_name".into(), + petname::petname(2, "-").expect("to be able to generate a valid petname"), + ); + } + agent::setup_config(discovery, force, setup_labels).await?; tracing::info!("wrote default agent config"); }