diff --git a/crankshaft-config/src/backend/generic/driver/shell.rs b/crankshaft-config/src/backend/generic/driver/shell.rs index 7f3468f..57dcc11 100644 --- a/crankshaft-config/src/backend/generic/driver/shell.rs +++ b/crankshaft-config/src/backend/generic/driver/shell.rs @@ -23,7 +23,7 @@ pub enum Shell { impl Shell { /// Gets a series of args that can be passed through to a driver for /// commands. - pub fn args(&self, args: I) -> impl Iterator + pub fn args(&self, args: I) -> impl Iterator + use where I: IntoIterator, { diff --git a/crankshaft-engine/src/service/runner/backend/generic.rs b/crankshaft-engine/src/service/runner/backend/generic.rs index c0b3894..2b6817b 100644 --- a/crankshaft-engine/src/service/runner/backend/generic.rs +++ b/crankshaft-engine/src/service/runner/backend/generic.rs @@ -152,38 +152,41 @@ impl crate::Backend for Backend { let output = driver.run(submit).await.unwrap(); // (2) Monitoring the output. - if let Some(ref regex) = job_id_regex { - let stdout = String::from_utf8_lossy(&output.stdout); - let captures = regex.captures_iter(&stdout).next().unwrap_or_else(|| { - panic!( - "could not match the job id regex within stdout: `{}`", - stdout - ) - }); - - // SAFETY: this will always unwrap, as the group is - // _required_ for the pattern to match. - let id = captures.get(1).map(|c| String::from(c.as_str())).unwrap(); - subtitutions.insert(String::from("job_id"), id); - - loop { - let monitor = config.resolve_monitor(&subtitutions).unwrap(); - let output = driver.run(monitor).await.unwrap(); - - if !output.status.success() { - outputs.push(output); - break; + match job_id_regex { + Some(ref regex) => { + let stdout = String::from_utf8_lossy(&output.stdout); + let captures = regex.captures_iter(&stdout).next().unwrap_or_else(|| { + panic!( + "could not match the job id regex within stdout: `{}`", + stdout + ) + }); + + // SAFETY: this will always unwrap, as the group is + // _required_ for the pattern to match. + let id = captures.get(1).map(|c| String::from(c.as_str())).unwrap(); + subtitutions.insert(String::from("job_id"), id); + + loop { + let monitor = config.resolve_monitor(&subtitutions).unwrap(); + let output = driver.run(monitor).await.unwrap(); + + if !output.status.success() { + outputs.push(output); + break; + } + + tokio::time::sleep(Duration::from_secs( + config + .monitor_frequency() + .unwrap_or(DEFAULT_MONITOR_FREQUENCY), + )) + .await; } - - tokio::time::sleep(Duration::from_secs( - config - .monitor_frequency() - .unwrap_or(DEFAULT_MONITOR_FREQUENCY), - )) - .await; } - } else { - outputs.push(output); + _ => { + outputs.push(output); + } } } diff --git a/crankshaft-engine/src/task/builder.rs b/crankshaft-engine/src/task/builder.rs index 5d7b136..3a0dfb1 100644 --- a/crankshaft-engine/src/task/builder.rs +++ b/crankshaft-engine/src/task/builder.rs @@ -96,15 +96,14 @@ impl Builder { inputs.extend(new); Some(inputs) } - None => { - if let Some(input) = new.next() { + None => match new.next() { + Some(input) => { let mut inputs = NonEmpty::new(input); inputs.extend(new); Some(inputs) - } else { - None } - } + _ => None, + }, }; self @@ -122,15 +121,14 @@ impl Builder { outputs.extend(new); Some(outputs) } - None => { - if let Some(output) = new.next() { + None => match new.next() { + Some(output) => { let mut outputs = NonEmpty::new(output); outputs.extend(new); Some(outputs) - } else { - None } - } + _ => None, + }, }; self @@ -159,15 +157,14 @@ impl Builder { executors.extend(new); Some(executors) } - None => { - if let Some(executor) = new.next() { + None => match new.next() { + Some(executor) => { let mut executors = NonEmpty::new(executor); executors.extend(new); Some(executors) - } else { - None } - } + _ => None, + }, }; self @@ -185,15 +182,14 @@ impl Builder { volumes.extend(new); Some(volumes) } - None => { - if let Some(volume) = new.next() { + None => match new.next() { + Some(volume) => { let mut volumes: NonEmpty<_> = NonEmpty::new(volume); volumes.extend(new); Some(volumes) - } else { - None } - } + _ => None, + }, }; self diff --git a/crankshaft-engine/src/task/execution/builder.rs b/crankshaft-engine/src/task/execution/builder.rs index 8fd0a18..cc51b75 100644 --- a/crankshaft-engine/src/task/execution/builder.rs +++ b/crankshaft-engine/src/task/execution/builder.rs @@ -89,15 +89,14 @@ impl Builder { args.extend(values); Some(args) } - None => { - if let Some(arg) = values.next() { + None => match values.next() { + Some(arg) => { let mut args = NonEmpty::new(arg); args.extend(values); Some(args) - } else { - None } - } + _ => None, + }, }; self diff --git a/crankshaft-engine/src/task/resources/builder.rs b/crankshaft-engine/src/task/resources/builder.rs index 36dcb65..7c21163 100644 --- a/crankshaft-engine/src/task/resources/builder.rs +++ b/crankshaft-engine/src/task/resources/builder.rs @@ -90,15 +90,14 @@ impl Builder { zones.extend(values); Some(zones) } - None => { - if let Some(zone) = values.next() { + None => match values.next() { + Some(zone) => { let mut zones = NonEmpty::new(zone); zones.extend(values); Some(zones) - } else { - None } - } + _ => None, + }, }; self