Skip to content

Commit

Permalink
feat: nativets can use the wmill library + setClient not required any…
Browse files Browse the repository at this point in the history
…more (#3714)

* all

* all

* all

* all
  • Loading branch information
rubenfiszel committed May 13, 2024
1 parent a60bc82 commit 8b21f08
Show file tree
Hide file tree
Showing 20 changed files with 56,773 additions and 67 deletions.
6 changes: 0 additions & 6 deletions backend/windmill-common/src/variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,6 @@ pub async fn get_reserved_variables(
description: "State resource path unique to a script and its trigger".to_string(),
is_custom: false,
},
ContextualVariable {
name: "WM_STATE_PATH_NEW".to_string(),
value: state_path,
description: "State resource path unique to a script and its trigger (legacy)".to_string(),
is_custom: false,
},
ContextualVariable {
name: "WM_FLOW_STEP_ID".to_string(),
value: step_id.unwrap_or_else(|| "".to_string()),
Expand Down
22 changes: 19 additions & 3 deletions backend/windmill-worker/src/js_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ pub struct LogString {
}

pub async fn eval_fetch_timeout(
env_code: String,
ts_expr: String,
js_expr: String,
args: Option<&Json<HashMap<String, Box<RawValue>>>>,
Expand Down Expand Up @@ -681,7 +682,7 @@ pub async fn eval_fetch_timeout(

let future = async {
tokio::select! {
r = eval_fetch(&mut js_runtime, &js_expr) => Ok(r),
r = eval_fetch(&mut js_runtime, &js_expr, Some(env_code)) => Ok(r),
_ = memory_limit_rx.recv() => Err(Error::ExecutionErr("Memory limit reached, killing isolate".to_string()))
}
};
Expand Down Expand Up @@ -722,11 +723,26 @@ pub async fn eval_fetch_timeout(
Ok(r)
}

async fn eval_fetch(js_runtime: &mut JsRuntime, expr: &str) -> anyhow::Result<Box<RawValue>> {
const WINDMILL_CLIENT: &str = include_str!("./windmill-client.js");

async fn eval_fetch(
js_runtime: &mut JsRuntime,
expr: &str,
env_code: Option<String>,
) -> anyhow::Result<Box<RawValue>> {
if let Some(env_code) = env_code.as_ref() {
let _ = js_runtime
.load_side_module(
&deno_core::resolve_url("file:///windmill.ts")?,
Some(format!("{env_code}\n{}", WINDMILL_CLIENT.to_string()).into()),
)
.await?;
}

let _ = js_runtime
.load_side_module(
&deno_core::resolve_url("file:///eval.ts")?,
Some(expr.to_string().into()),
Some(format!("{}\n{expr}", env_code.unwrap_or_default()).into()),
)
.await?;

Expand Down
6 changes: 4 additions & 2 deletions backend/windmill-worker/src/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ globalThis.FileReader = fileReader.FileReader;
globalThis.console = new console.Console((msg, level) =>
globalThis.Deno.core.ops.op_log(msg)
);
globalThis.AbortController = abortSignal.AbortController;
globalThis.AbortSignal = abortSignal.AbortSignal;
// Object.assign(globalThis, {
// console: nonEnumerable(
// new console.Console((msg, level) => core.print(msg, level > 1))
Expand Down Expand Up @@ -122,8 +124,8 @@ globalThis.console = new console.Console((msg, level) =>
// FormData: nonEnumerable(formData.FormData),

// // abort signal
// AbortController: nonEnumerable(abortSignal.AbortController),
// AbortSignal: nonEnumerable(abortSignal.AbortSignal),
// AbortController: nonEnumerable(abortSignal.AbortController),
// AbortSignal: nonEnumerable(abortSignal.AbortSignal),

// // // web sockets
// // WebSocket: nonEnumerable(webSocket.WebSocket),
Expand Down

0 comments on commit 8b21f08

Please sign in to comment.