diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 0a8f859ace..478302f554 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -9571,6 +9571,7 @@ dependencies = [ "itertools 0.12.0", "lazy_static", "prometheus", + "regex", "reqwest", "rsmq_async", "serde", diff --git a/backend/windmill-queue/Cargo.toml b/backend/windmill-queue/Cargo.toml index 5946bcabf3..c1d537a39a 100644 --- a/backend/windmill-queue/Cargo.toml +++ b/backend/windmill-queue/Cargo.toml @@ -39,4 +39,5 @@ itertools.workspace = true async-recursion.workspace = true bigdecimal.workspace = true axum.workspace = true -serde_urlencoded.workspace = true \ No newline at end of file +serde_urlencoded.workspace = true +regex.workspace = true \ No newline at end of file diff --git a/backend/windmill-queue/src/jobs.rs b/backend/windmill-queue/src/jobs.rs index 952442fb56..22963eb784 100644 --- a/backend/windmill-queue/src/jobs.rs +++ b/backend/windmill-queue/src/jobs.rs @@ -25,6 +25,7 @@ use bigdecimal::ToPrimitive; use chrono::{DateTime, Duration, Utc}; use itertools::Itertools; use prometheus::IntCounter; +use regex::Regex; use reqwest::{ header::{HeaderMap, CONTENT_TYPE}, Client, StatusCode, @@ -2292,6 +2293,10 @@ impl From>> for PushArgs( _db: &Pool, @@ -2872,13 +2877,32 @@ pub async fn push<'c, T: Serialize + Send + Sync, R: rsmq_async::RsmqConnection "deno".to_string() } }; - tag.map(|x| x.as_str().replace("$workspace", workspace_id).to_string()) - .unwrap_or_else(|| { - language - .as_ref() - .map(|x| x.as_str().to_string()) - .unwrap_or_else(default) - }) + let interpolated_tag = tag.map(|x| { + let workspaced = x.as_str().replace("$workspace", workspace_id).to_string(); + if RE_ARG_TAG.is_match(&workspaced) { + let mut interpolated = workspaced.clone(); + for cap in RE_ARG_TAG.captures_iter(&workspaced) { + let arg_name = cap.get(1).unwrap().as_str(); + let value = serde_json::to_value(&args).unwrap_or_default(); + let arg_value = value + .get(arg_name) + .and_then(|x| x.as_str()) + .unwrap_or_default(); + interpolated = + interpolated.replace(format!("$args[{}]", arg_name).as_str(), arg_value); + } + interpolated + } else { + workspaced + } + }); + + interpolated_tag.unwrap_or_else(|| { + language + .as_ref() + .map(|x| x.as_str().to_string()) + .unwrap_or_else(default) + }) }; let mut tx = match tx {