fix: improve dedicated workers for flows

This commit is contained in:
Ruben Fiszel
2024-07-04 16:34:35 +02:00
parent ecf7db5534
commit 1e3523cd79
2 changed files with 13 additions and 4 deletions
+1 -1
View File
@@ -1141,7 +1141,7 @@ pub async fn handle_child(
if let Err(err) = result {
tracing::error!(%job_id, %err, "error reading output for job {job_id}: {err}");
tracing::error!(%job_id, %err, "error reading output for job {job_id} '{child_name}': {err}");
break;
}
@@ -487,6 +487,8 @@ pub async fn create_dedicated_worker_map(
(HashMap::new(), false, dedicated_handles)
}
}
#[derive(Debug, Clone)]
pub enum SpawnWorker {
Script { path: String, hash: Option<ScriptHash> },
RawScript { path: String, content: String, lock: Option<String>, lang: ScriptLang },
@@ -532,7 +534,14 @@ async fn spawn_dedicated_worker(
let base_internal_url = base_internal_url.to_string();
let worker_name = worker_name.to_string();
let job_completed_tx = job_completed_tx.clone();
let job_dir = format!("{}/dedicated", worker_dir);
let job_dir = format!(
"{}/dedicated{}",
worker_dir,
node_id
.as_ref()
.map(|x| format!("-{x}"))
.unwrap_or_else(|| "".to_string())
);
tokio::fs::create_dir_all(&job_dir)
.await
.expect("create dir");
@@ -545,7 +554,7 @@ async fn spawn_dedicated_worker(
let path2 = path.clone();
let w_id = w_id.to_string();
let (content, lock, language, envs, codebase) = match sw {
let (content, lock, language, envs, codebase) = match sw.clone() {
SpawnWorker::Script { path, hash } => {
let q = if let Some(hash) = hash {
get_script_content_by_hash(&hash, &w_id, &db).await.map(
@@ -675,7 +684,7 @@ async fn spawn_dedicated_worker(
}
_ => unreachable!("Non supported language for dedicated worker"),
} {
tracing::error!("error in dedicated worker: {:?}", e);
tracing::error!("error in dedicated worker for {sw:#?}: {:?}", e);
};
if let Err(e) = killpill_tx.clone().send(()) {
tracing::error!("failed to send final killpill to dedicated worker: {:?}", e);