Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3769230
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/runner/mod.rs b/src/runner/mod.rs
index 4e602e1..61f58da 100644
--- a/src/runner/mod.rs
+++ b/src/runner/mod.rs
@@ -1,105 +1,105 @@
// -------------------------------------------------------------
// Alkane :: Runner
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Project: Nasqueron
// License: BSD-2-Clause
// Description: Run a recipe to initialize or update a site
// -------------------------------------------------------------
use std::ffi::OsStr;
use std::fmt::{Debug, Display};
use std::process::Command;
use log::{error, info, warn};
use serde::Serialize;
// -------------------------------------------------------------
// Modules
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
pub mod site;
pub mod store;
// -------------------------------------------------------------
// Exit status of a recipe.
//
// The executable called to build the site should use
// those exit code inspired by the Nagios one.
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#[derive(Debug, Serialize, PartialEq)]
pub enum RecipeStatus {
Success,
Warning,
Error,
Unknown,
}
impl RecipeStatus {
pub fn from_status_code(code: i32) -> Self {
match code {
0 => RecipeStatus::Success,
1 => RecipeStatus::Warning,
2 => RecipeStatus::Error,
_ => RecipeStatus::Unknown,
}
}
pub fn to_status_code(&self) -> i32 {
match self {
RecipeStatus::Success => 0,
RecipeStatus::Warning => 1,
RecipeStatus::Error => 2,
RecipeStatus::Unknown => 3,
}
}
}
// -------------------------------------------------------------
// Run an executable, returns the recipe status
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
pub fn run<E, I, S>(command: S, args: I, environment: E) -> RecipeStatus
where
E: IntoIterator<Item = (S, S)>,
I: IntoIterator<Item = S> + Debug,
S: AsRef<OsStr> + Display,
{
info!("Running command {} with args {:?}", command, args);
let result = Command::new(command).args(args).envs(environment).output();
match result {
Ok(process_output) => {
let stdout = read_bytes(&process_output.stdout);
let stderr = read_bytes(&process_output.stderr);
if !stdout.is_empty() {
info!("Channel stdout: {}", stdout);
}
if !stderr.is_empty() {
warn!("Channel stderr: {}", stderr);
}
match process_output.status.code() {
None => {
- warn!("Process terminated by signal.");
+ warn!("Process hard stopped by signal.");
RecipeStatus::Unknown
}
Some(code) => RecipeStatus::from_status_code(code),
}
}
Err(error) => {
error!("Process can't spawn: {:?}", error);
RecipeStatus::Error
}
}
}
fn read_bytes(bytes: &Vec<u8>) -> String {
String::from_utf8_lossy(bytes).to_string()
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Nov 25, 13:50 (1 d, 8 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2258149
Default Alt Text
(3 KB)
Attached To
Mode
rALK Alkane
Attached
Detach File
Event Timeline
Log In to Comment