diff --git a/databuild/job_run.rs b/databuild/job_run.rs index 965694e..c975286 100644 --- a/databuild/job_run.rs +++ b/databuild/job_run.rs @@ -21,6 +21,11 @@ pub trait JobRunBackend: Sized { /// Create a new not-started job run fn create(entry_point: String, args: Vec) -> Self::NotStartedState; + /// Convenience method to spawn a new job run (calls create and wraps in JobRun) + fn spawn(entry_point: String, args: Vec) -> NotStartedJobRun { + NotStartedJobRun::spawn(entry_point, args) + } + /// Transition from NotStarted to Running fn start( not_started: Self::NotStartedState, @@ -311,7 +316,7 @@ pub struct JobRunPollResult { mod tests { use std::collections::HashMap; use crate::data_build_event::Event; - use crate::job_run::{JobRunVisitResult, NotStartedJobRun, SubProcessBackend}; + use crate::job_run::{JobRunBackend, JobRunVisitResult, NotStartedJobRun, SubProcessBackend}; use crate::{ManuallyTriggeredEvent}; fn test_helper_path() -> String { @@ -324,7 +329,7 @@ mod tests { #[test] fn test_job_run_success_returns_job_run_success_event() { // Spawn a job run that will succeed (exit code 0) - let job_run: NotStartedJobRun = 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 let mut running_job = job_run.run().unwrap(); @@ -354,7 +359,7 @@ mod tests { #[test] fn test_job_run_failure_returns_job_run_failure_event() { // Spawn a job run - let job_run: NotStartedJobRun = 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) let env: HashMap = HashMap::from([ @@ -396,7 +401,7 @@ mod tests { 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 - let job_run: NotStartedJobRun = NotStartedJobRun::spawn(test_helper_path(), vec![]); + let job_run = SubProcessBackend::spawn(test_helper_path(), vec![]); let env: HashMap = HashMap::from([ ("DATABUILD_TEST_SLEEP_MS".to_string(), "1000".to_string()),