INNER CODE UNIT · Rust
get_job_index
ngless-toolkit/ngless · src/batch.rs:35
pub fn get_job_index() -> Option<i64> {
get_int_from_env("LSB_JOBINDEX").or_else(|| get_int_from_env("SGE_TASK_ID"))
}
/// Read an environment variable and parse it as an integer, mirroring `(>>= readMaybe) <$>
/// lookupEnv`: an unset variable or an unparseable value both yield `None`.
fn get_int_from_env<T: std::str::FromStr>(var: &str) -> Option<T> {
env::var(var).ok().and_then(|v| v.parse().ok())
}
#[cfg(test)]
mod tests {
use super::*;
// All `batch` environment variables, cleared around each assertion. These variables are not
// touched by any other test, but env mutation is process-global, so everything runs inside one
// test function to keep it deterministic regardless of test-thread scheduling.
const VARS: &[&str] = &[