little tweak to job run constructor
This commit is contained in:
parent
eeb90d0386
commit
1f4138ecc0
1 changed files with 9 additions and 4 deletions
|
|
@ -21,6 +21,11 @@ pub trait JobRunBackend: Sized {
|
||||||
/// Create a new not-started job run
|
/// Create a new not-started job run
|
||||||
fn create(entry_point: String, args: Vec<String>) -> Self::NotStartedState;
|
fn create(entry_point: String, args: Vec<String>) -> Self::NotStartedState;
|
||||||
|
|
||||||
|
/// Convenience method to spawn a new job run (calls create and wraps in JobRun)
|
||||||
|
fn spawn(entry_point: String, args: Vec<String>) -> NotStartedJobRun<Self> {
|
||||||
|
NotStartedJobRun::spawn(entry_point, args)
|
||||||
|
}
|
||||||
|
|
||||||
/// Transition from NotStarted to Running
|
/// Transition from NotStarted to Running
|
||||||
fn start(
|
fn start(
|
||||||
not_started: Self::NotStartedState,
|
not_started: Self::NotStartedState,
|
||||||
|
|
@ -311,7 +316,7 @@ pub struct JobRunPollResult {
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use crate::data_build_event::Event;
|
use crate::data_build_event::Event;
|
||||||
use crate::job_run::{JobRunVisitResult, NotStartedJobRun, SubProcessBackend};
|
use crate::job_run::{JobRunBackend, JobRunVisitResult, NotStartedJobRun, SubProcessBackend};
|
||||||
use crate::{ManuallyTriggeredEvent};
|
use crate::{ManuallyTriggeredEvent};
|
||||||
|
|
||||||
fn test_helper_path() -> String {
|
fn test_helper_path() -> String {
|
||||||
|
|
@ -324,7 +329,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_job_run_success_returns_job_run_success_event() {
|
fn test_job_run_success_returns_job_run_success_event() {
|
||||||
// Spawn a job run that will succeed (exit code 0)
|
// Spawn a job run that will succeed (exit code 0)
|
||||||
let job_run: NotStartedJobRun<SubProcessBackend> = NotStartedJobRun::spawn(test_helper_path(), vec![]);
|
let job_run = SubProcessBackend::spawn(test_helper_path(), vec![]);
|
||||||
|
|
||||||
// Start the job - this consumes the NotStarted and returns Running
|
// Start the job - this consumes the NotStarted and returns Running
|
||||||
let mut running_job = job_run.run().unwrap();
|
let mut running_job = job_run.run().unwrap();
|
||||||
|
|
@ -354,7 +359,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_job_run_failure_returns_job_run_failure_event() {
|
fn test_job_run_failure_returns_job_run_failure_event() {
|
||||||
// Spawn a job run
|
// Spawn a job run
|
||||||
let job_run: NotStartedJobRun<SubProcessBackend> = NotStartedJobRun::spawn(test_helper_path(), vec![]);
|
let job_run = SubProcessBackend::spawn(test_helper_path(), vec![]);
|
||||||
|
|
||||||
// Start the job with an exit code that indicates failure (non-zero)
|
// Start the job with an exit code that indicates failure (non-zero)
|
||||||
let env: HashMap<String, String> = HashMap::from([
|
let env: HashMap<String, String> = HashMap::from([
|
||||||
|
|
@ -396,7 +401,7 @@ mod tests {
|
||||||
let temp_file = format!("/tmp/databuild_test_cancel_{}", Uuid::new_v4());
|
let temp_file = format!("/tmp/databuild_test_cancel_{}", Uuid::new_v4());
|
||||||
|
|
||||||
// Spawn a job run that will sleep for 1 second and write a file
|
// Spawn a job run that will sleep for 1 second and write a file
|
||||||
let job_run: NotStartedJobRun<SubProcessBackend> = NotStartedJobRun::spawn(test_helper_path(), vec![]);
|
let job_run = SubProcessBackend::spawn(test_helper_path(), vec![]);
|
||||||
|
|
||||||
let env: HashMap<String, String> = HashMap::from([
|
let env: HashMap<String, String> = HashMap::from([
|
||||||
("DATABUILD_TEST_SLEEP_MS".to_string(), "1000".to_string()),
|
("DATABUILD_TEST_SLEEP_MS".to_string(), "1000".to_string()),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue