diff --git a/backend/windmill-worker/src/worker.rs b/backend/windmill-worker/src/worker.rs index 5e3523de0d..1d715464a0 100644 --- a/backend/windmill-worker/src/worker.rs +++ b/backend/windmill-worker/src/worker.rs @@ -12,7 +12,7 @@ use itertools::Itertools; use once_cell::sync::OnceCell; use serde::Deserialize; use sqlx::{Pool, Postgres}; -use windmill_api_client::Client; +use windmill_api_client::{Client, types::CompletedJob}; use windmill_parser::Typ; use std::{ borrow::Borrow, collections::HashMap, io, os::unix::process::ExitStatusExt, panic, @@ -673,7 +673,7 @@ pub async fn run_worker windmill_common::error::Result { + let http_args: HttpArgs = serde_json::from_value(job.args.clone().unwrap_or_else(|| json!({}))) + .map_err(|e| Error::ExecutionErr(e.to_string()))?; + let res = HTTP_CLIENT.get(http_args.url).send().await.map_err(|e| Error::ExecutionErr(format!("Invalid http request: {e}")))?; + let res = if res.headers().get("Content-Type").is_some_and(|x| x == "application/json") { + res.json().await.map_err(|e| Error::ExecutionErr(format!("Invalid http response: {e}")))? + } else { + serde_json::Value::String(res.text().await.map_err(|e| Error::ExecutionErr(format!("Invalid http response: {e}")))?) + }; + return Ok(JobCompleted { + job: job, + result: res, + logs: "".to_string(), + }); +} #[tracing::instrument(level = "trace", skip_all)] async fn handle_queued_job( job: QueuedJob, @@ -928,6 +943,13 @@ async fn handle_queued_job( .await?; } _ => { + if matches!(job.job_kind, JobKind::Http) { + tokio::task::spawn(async move { + let jc = do_http_req(job).await.expect("do http req"); + job_completed_tx.send(jc).await.expect("send job completed"); + }); + return Ok(()); + } let mut logs = "".to_string(); // println!("handle queue {:?}", SystemTime::now()); if let Some(log_str) = &job.logs { @@ -1016,14 +1038,7 @@ async fn handle_queued_job( args @ _ => Ok(args.unwrap_or_else(|| Value::Null)), }, JobKind::Http => { - let http_args: HttpArgs = serde_json::from_value(job.args.clone().unwrap_or_else(|| json!({}))) - .map_err(|e| Error::ExecutionErr(e.to_string()))?; - let res = HTTP_CLIENT.get(http_args.url).send().await.map_err(|e| Error::ExecutionErr(format!("Invalid http request: {e}")))?; - if res.headers().get("Content-Type").is_some_and(|x| x == "application/json") { - Ok(res.json().await.map_err(|e| Error::ExecutionErr(format!("Invalid http response: {e}")))?) - } else { - Ok(serde_json::Value::String(res.text().await.map_err(|e| Error::ExecutionErr(format!("Invalid http response: {e}")))?)) - } + panic!("should not be here") }, JobKind::Graphql => todo!(), JobKind::Postgresql => todo!(), @@ -1041,7 +1056,7 @@ async fn handle_queued_job( .await } } - }; + }; //it's a test job, no need to update the db if job.workspace_id == "" { diff --git a/benchmarks/main.ts b/benchmarks/main.ts index 32dd5d6887..b1a25266c2 100644 --- a/benchmarks/main.ts +++ b/benchmarks/main.ts @@ -97,7 +97,7 @@ await new Command() ) .option( "--script-pattern ", - "Use a different script pattern among: denotrivial, identity, httpversion (Default denotrivial)" + "Use a different script pattern among: denotrivial, identity, httpversion, httpslow (Default denotrivial)" ) .option("--custom ", "Use custom actions during bench") .option( diff --git a/benchmarks/worker.ts b/benchmarks/worker.ts index f2b60fb7d2..2f955d1325 100644 --- a/benchmarks/worker.ts +++ b/benchmarks/worker.ts @@ -170,7 +170,16 @@ while (cont) { path: "httpversion", kind: "http", args: { - url: "https://google.com", + url: "http://localhost:8000/api/version", + }, + }; + } + if (config.scriptPattern == "httpslow") { + payload = { + path: "httpversion", + kind: "http", + args: { + url: "https://hub.dummyapis.com/delay?seconds=10", }, }; } else if (config.scriptPattern == "identity") { @@ -239,8 +248,9 @@ while (outstanding.length > 0 && Date.now() < end_time) { r = r as api.CompletedJob; try { if ( - config.scriptPattern != "httpversion" && - config.scriptPattern != "identity" && + !["httpversion", "identity", "httpslow"].includes( + config.scriptPattern + ) && r.result != uuid ) { console.log(