fix(go): put shared directory in job dir and not go parent

This commit is contained in:
Ruben Fiszel
2024-09-19 10:05:08 +02:00
parent ff49b8323d
commit 57a6beaed2
3 changed files with 25 additions and 23 deletions
+7 -8
View File
@@ -1,12 +1,8 @@
use std::{collections::HashMap, process::Stdio};
use std::{collections::HashMap, fs::DirBuilder, process::Stdio};
use itertools::Itertools;
use serde_json::value::RawValue;
use tokio::{
fs::{create_dir, DirBuilder, File},
io::AsyncReadExt,
process::Command,
};
use tokio::{fs::File, io::AsyncReadExt, process::Command};
use uuid::Uuid;
use windmill_common::{
error::{self, Error},
@@ -51,6 +47,11 @@ pub async fn handle_go_job(
) -> Result<Box<RawValue>, Error> {
//go does not like executing modules at temp root
let job_dir = &format!("{job_dir}/go");
DirBuilder::new()
.recursive(true)
.create(&job_dir)
.expect("could not create go job dir");
let hash = calculate_hash(&format!(
"{}{}v2",
inner_content,
@@ -64,7 +65,6 @@ pub async fn handle_go_job(
let (cache, cache_logs) = windmill_common::worker::load_cache(&bin_path, &remote_path).await;
let (skip_go_mod, skip_tidy) = if cache {
create_dir(job_dir).await?;
(true, true)
} else if let Some(requirements) = requirements_o {
gen_go_mod(inner_content, job_dir, &requirements).await?
@@ -467,7 +467,6 @@ async fn gen_go_mymod(code: &str, job_dir: &str) -> error::Result<()> {
DirBuilder::new()
.recursive(true)
.create(&mymod_dir)
.await
.expect("could not create go's mymod dir");
write_file(&mymod_dir, "inner_main.go", &code)?;
+17 -14
View File
@@ -32,13 +32,10 @@ use reqwest::Response;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use sqlx::{types::Json, Pool, Postgres};
use std::{
collections::{hash_map::DefaultHasher, HashMap},
hash::Hash,
sync::{
collections::{hash_map::DefaultHasher, HashMap}, fs::DirBuilder, hash::Hash, sync::{
atomic::{AtomicBool, AtomicU16, Ordering},
Arc,
},
time::Duration,
}, time::Duration
};
#[cfg(feature = "benchmark")]
use std::sync::atomic::AtomicUsize;
@@ -74,7 +71,6 @@ use tokio::fs::symlink;
use tokio::fs::symlink_file as symlink;
use tokio::{
fs::DirBuilder,
sync::{
mpsc::{self, Sender},
RwLock,
@@ -736,7 +732,6 @@ pub async fn run_worker<R: rsmq_async::RsmqConnection + Send + Sync + Clone + 's
DirBuilder::new()
.recursive(true)
.create(&worker_dir)
.await
.expect("could not create initial worker dir");
if !*DISABLE_NSJAIL {
@@ -1655,12 +1650,21 @@ pub async fn run_worker<R: rsmq_async::RsmqConnection + Send + Sync + Clone + 's
DirBuilder::new()
.recursive(true)
.create(&job_dir)
.await
.expect("could not create job dir");
let same_worker = job.same_worker;
let target = &format!("{job_dir}/shared");
let folder = if job.language == Some(ScriptLang::Go) {
DirBuilder::new()
.recursive(true)
.create(&format!("{job_dir}/go"))
.expect("could not create go dir");
"/go"
} else {
""
};
let target = &format!("{job_dir}{folder}/shared");
if same_worker && job.parent_job.is_some() {
if tokio::fs::metadata(target).await.is_err() {
@@ -1669,7 +1673,6 @@ pub async fn run_worker<R: rsmq_async::RsmqConnection + Send + Sync + Clone + 's
DirBuilder::new()
.recursive(true)
.create(&parent_shared_dir)
.await
.expect("could not create parent shared dir");
symlink(&parent_shared_dir, target)
@@ -1680,7 +1683,6 @@ pub async fn run_worker<R: rsmq_async::RsmqConnection + Send + Sync + Clone + 's
DirBuilder::new()
.recursive(true)
.create(target)
.await
.expect("could not create shared dir");
}
@@ -2663,11 +2665,12 @@ async fn handle_code_execution_job(
);
let shared_mount = if job.same_worker && job.language != Some(ScriptLang::Deno) {
let folder = if job.language == Some(ScriptLang::Go) { "/go" } else { "" };
format!(
r#"
mount {{
src: "{job_dir}/shared"
dst: "/tmp/shared"
src: "{job_dir}{folder}/shared"
dst: "/tmp{folder}/shared"
is_bind: true
rw: true
}}
@@ -477,7 +477,7 @@
options={{
right: 'Send an alert when the number of alive workers falls below a given threshold'
}}
checked={nconfig?.min_alive_workers_alert_threshold !== undefined ?? false}
checked={nconfig?.min_alive_workers_alert_threshold !== undefined}
on:change={(ev) => {
if (nconfig !== undefined) {
nconfig.min_alive_workers_alert_threshold = ev.detail ? 1 : undefined