Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

Commit

Permalink
WIP #60 get executor working on task lists
Browse files Browse the repository at this point in the history
  • Loading branch information
ninjabear committed Sep 27, 2016
1 parent 3ecd18f commit 2781fc1
Show file tree
Hide file tree
Showing 7 changed files with 382 additions and 263 deletions.
43 changes: 27 additions & 16 deletions src/factotum/executor/execution_strategy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,23 @@ use super::*;
use std::process::Command;
use chrono::UTC;
use std::time::Duration;
use super::task_list::RunResult;
use chrono::DateTime;

pub struct RunResult {
pub run_started: DateTime<UTC>,
pub duration: Duration,
pub task_execution_error: Option<String>,
pub stdout: Option<String>,
pub stderr: Option<String>,
pub return_code: i32
}

// pub struct TaskExecutionResult {
// pub name: String,
// pub attempted: bool,
// pub run_details: Option<RunResult>
// }


pub struct CommandRequest {
name: String,
Expand All @@ -34,7 +50,7 @@ impl CommandRequest {


pub trait ExecutionStrategy {
fn execute(&self, command_request:&CommandRequest) -> TaskExecutionResult;
fn execute(&self, command_request:&CommandRequest) -> RunResult;
}

pub struct Simulation;
Expand All @@ -46,19 +62,14 @@ impl Simulation {
}

impl ExecutionStrategy for Simulation {
fn execute(&self, command_request:&CommandRequest) -> TaskExecutionResult {
TaskExecutionResult {
name: command_request.name.clone(),
attempted: true,
run_details: Some(RunResult {
run_started: UTC::now(),
duration: Duration::from_secs(0),
requests_job_termination: false,
task_execution_error: None,
stdout: Some(format!("Execute {:?}", command_request.command)),
stderr: None,
return_code: -1
})
fn execute(&self, command_request:&CommandRequest) -> RunResult {
RunResult {
run_started: UTC::now(),
duration: Duration::from_secs(0),
task_execution_error: None,
stdout: Some(format!("Execute {:?}", command_request.command)),
stderr: None,
return_code: -1
}
}
}
Expand All @@ -70,7 +81,7 @@ impl OSExecution {
}

impl ExecutionStrategy for OSExecution {
fn execute(&self, command_request:&CommandRequest) -> TaskExecutionResult {
fn execute(&self, command_request:&CommandRequest) -> RunResult {
unreachable!("finish me");
}
}
17 changes: 5 additions & 12 deletions src/factotum/executor/execution_strategy/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,11 @@ use chrono::duration::Duration;
command.arg("hello_world");
let result = execution_strategy_simulate.execute(&CommandRequest::new("hello-world", command));

assert_eq!(result.name, "hello-world");
assert_eq!(result.attempted, true);
if let Some(run_result) = result.run_details {
assert_eq!(run_result.return_code, -1);
assert!(run_result.run_started > UTC::now().checked_sub(Duration::seconds(60)).unwrap());
assert_eq!(run_result.duration, Duration::seconds(0).to_std().ok().unwrap());
assert!(!run_result.requests_job_termination);
assert_eq!(run_result.stdout.unwrap(), "Execute \"banana\" \"hello_world\"");
assert!(run_result.stderr.is_some()==false)
} else {
unreachable!("No run result attached")
}
assert_eq!(result.return_code, -1);
assert!(result.run_started > UTC::now().checked_sub(Duration::seconds(60)).unwrap());
assert_eq!(result.duration, Duration::seconds(0).to_std().ok().unwrap());
assert_eq!(result.stdout.unwrap(), "Execute \"banana\" \"hello_world\"");
assert!(result.stderr.is_some()==false)
}

#[test]
Expand Down
Loading

0 comments on commit 2781fc1

Please sign in to comment.