Skip to content

Commit

Permalink
fix: improve status exit dedicated workers
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenfiszel committed May 11, 2024
1 parent f835ce2 commit 12e302a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 27 deletions.
9 changes: 4 additions & 5 deletions backend/windmill-common/src/ee.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::ee::LicensePlan::Community;
use serde::{Deserialize, Serialize};
use serde::Deserialize;
use std::sync::Arc;
use tokio::sync::RwLock;

Expand All @@ -20,9 +20,8 @@ pub async fn get_license_plan() -> LicensePlan {
return Community;
}

#[derive(Serialize, Deserialize)]
#[derive(Deserialize)]
#[serde(untagged)]
pub enum CriticalErrorChannel {}

pub async fn trigger_critical_error_channels(_msg: String) {
// Implementation is not open source
}
pub async fn trigger_critical_error_channels(_error_message: String) {}
42 changes: 22 additions & 20 deletions backend/windmill-worker/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use windmill_queue::{append_logs, CanceledBy};
#[cfg(any(target_os = "linux", target_os = "macos"))]
use std::os::unix::process::ExitStatusExt;

use std::process::ExitStatus;
use std::sync::atomic::AtomicU32;
use std::sync::Arc;
use std::{
Expand Down Expand Up @@ -1145,33 +1146,34 @@ pub async fn handle_child(
_ if *too_many_logs.borrow() => Err(Error::ExecutionErr(format!(
"logs or result reached limit. (current max size: {MAX_RESULT_SIZE} characters)"
))),
Ok(Ok(status)) => {
if status.success() {
Ok(())
} else if let Some(code) = status.code() {
Err(error::Error::ExitStatus(code))
} else {
#[cfg(any(target_os = "linux", target_os = "macos"))]
return Err(error::Error::ExecutionErr(format!(
"process terminated by signal: {:#?}, stopped_signal: {:#?}, core_dumped: {}",
status.signal(),
status.stopped_signal(),
status.core_dumped()
)));

#[cfg(not(any(target_os = "linux", target_os = "macos")))]
return Err(error::Error::ExecutionErr(String::from(
"process terminated by signal",
)));
}
}
Ok(Ok(status)) => process_status(status),
Ok(Err(kill_reason)) => Err(Error::ExecutionErr(format!(
"job process killed because {kill_reason:#?}"
))),
Err(err) => Err(Error::ExecutionErr(format!("job process io error: {err}"))),
}
}

pub fn process_status(status: ExitStatus) -> error::Result<()> {
if status.success() {
Ok(())
} else if let Some(code) = status.code() {
Err(error::Error::ExitStatus(code))
} else {
#[cfg(any(target_os = "linux", target_os = "macos"))]
return Err(error::Error::ExecutionErr(format!(
"process terminated by signal: {:#?}, stopped_signal: {:#?}, core_dumped: {}",
status.signal(),
status.stopped_signal(),
status.core_dumped()
)));

#[cfg(not(any(target_os = "linux", target_os = "macos")))]
return Err(error::Error::ExecutionErr(String::from(
"process terminated by signal",
)));
}
}
pub async fn start_child_process(mut cmd: Command, executable: &str) -> Result<Child, Error> {
return cmd
.spawn()
Expand Down
9 changes: 7 additions & 2 deletions backend/windmill-worker/src/dedicated_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ use std::{collections::VecDeque, process::Stdio, sync::Arc};
use anyhow::Context;

use crate::{
common::start_child_process, JobCompleted, JobCompletedSender, MAX_BUFFERED_DEDICATED_JOBS,
common::{process_status, start_child_process},
JobCompleted, JobCompletedSender, MAX_BUFFERED_DEDICATED_JOBS,
};

use futures::{future, Future};
Expand Down Expand Up @@ -108,7 +109,11 @@ pub async fn handle_dedicated_process(
.wait()
.await
.expect("child process encountered an error");
tracing::info!("child status was: {}", status);
if let Err(e) = process_status(status) {
tracing::error!("child exit status was not success: {e}");
} else {
tracing::info!("child exist status was success");
}
});

let mut jobs = VecDeque::with_capacity(MAX_BUFFERED_DEDICATED_JOBS);
Expand Down

0 comments on commit 12e302a

Please sign in to comment.