Skip to content

Commit

Permalink
fix: bun scripts cached in docker image have their dependencies pre-l…
Browse files Browse the repository at this point in the history
…oaded
  • Loading branch information
rubenfiszel committed Sep 9, 2024
1 parent 9329006 commit 4a6c3c8
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 116 deletions.
31 changes: 29 additions & 2 deletions backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,49 @@ async fn cache_hub_scripts(file_path: Option<String>) -> anyhow::Result<()> {
for path in paths.values() {
tracing::info!("Caching hub script at {path}");
let res = get_hub_script_content_and_requirements(Some(path.to_string()), None).await?;
if res.language.is_some_and(|x| x == ScriptLang::Deno) {
if res
.language
.as_ref()
.is_some_and(|x| x == &ScriptLang::Deno)
{
let job_dir = format!("{}/cache_init/{}", TMP_DIR, Uuid::new_v4());
create_dir_all(&job_dir).await?;
let _ = windmill_worker::generate_deno_lock(
&Uuid::nil(),
&res.content,
&mut 0,
&mut None,
"/tmp/windmill/",
&job_dir,
None,
"global",
"global",
"",
)
.await?;
tokio::fs::remove_dir_all(job_dir).await?;
} else if res.language.as_ref().is_some_and(|x| x == &ScriptLang::Bun) {
let job_id = Uuid::new_v4();
let job_dir = format!("{}/cache_init/{}", TMP_DIR, job_id);
create_dir_all(&job_dir).await?;
if let Some(lockfile) = res.lockfile {
let _ = windmill_worker::prepare_job_dir(&lockfile, &job_dir).await?;

let _ = windmill_worker::install_bun_lockfile(
&mut 0,
&mut None,
&job_id,
"admins",
None,
&job_dir,
"cache_init",
windmill_worker::get_common_bun_proc_envs("").await,
false,
)
.await?;
} else {
tracing::warn!("No lockfile found for bun script {path}, skipping...");
}
tokio::fs::remove_dir_all(job_dir).await?;
}
}
Ok(())
Expand Down
19 changes: 10 additions & 9 deletions backend/windmill-queue/src/jobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2253,8 +2253,8 @@ pub async fn get_result_by_id(
job.parse_flow_status()
.map(|status| status.restarted_from)
.flatten(),
"Flow result by id in leaf jobs",
format!("{}, {}", flow_id, node_id),
"Id not found in the result's mapping of the root job and root job had no restarted from information",
format!("parent: {}, root: {}, id: {}", flow_id, job.id, node_id),
)?;

get_result_by_id_from_original_flow(
Expand Down Expand Up @@ -2305,8 +2305,8 @@ pub async fn get_result_by_id_from_running_flow(

let flow_job_result = windmill_common::utils::not_found_if_none(
flow_job_result,
"Flow result by id in leaf jobs",
format!("{}, {}", flow_id, node_id),
"Root job of parent runnnig flow",
format!("parent: {}, id: {}", flow_id, node_id),
)?;

let job_result = flow_job_result
Expand All @@ -2327,7 +2327,7 @@ pub async fn get_result_by_id_from_running_flow(
let result_id = windmill_common::utils::not_found_if_none(
job_result,
"Flow result by id",
format!("{}, {}", flow_id, node_id),
format!("parent: {}, id: {}", flow_id, node_id),
)?;

extract_result_from_job_result(db, w_id, result_id, json_path).await
Expand Down Expand Up @@ -2369,7 +2369,8 @@ async fn get_completed_flow_node_result_rec(
.await
.map(Some),
_ => Err(error::Error::NotFound(format!(
"Flow result by id in leaf jobs not found at name {}",
"Flow result by id not found going top-down in subflows (currently: {}), (id: {})",
subflow.id,
node_id,
))),
};
Expand Down Expand Up @@ -2406,14 +2407,14 @@ async fn get_result_by_id_from_original_flow(

let flow_job = windmill_common::utils::not_found_if_none(
flow_job,
"Flow result by id in leaf jobs",
format!("{}, {}", completed_flow_id, node_id),
"Root completed job",
format!("root: {}, id: {}", completed_flow_id, node_id),
)?;

match get_completed_flow_node_result_rec(db, w_id, vec![flow_job], node_id, json_path).await? {
Some(res) => Ok(res),
None => Err(error::Error::NotFound(format!(
"Flow result by id in leaf jobs not found at name {}, {}",
"Flow result by id not found going top-down from {}, (id: {})",
completed_flow_id, node_id
))),
}
Expand Down
Loading

0 comments on commit 4a6c3c8

Please sign in to comment.