From ae2351594f7c42d94de3166699fdccf874d107be Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Wed, 17 Jul 2024 20:26:16 -0700 Subject: [PATCH] job: Move add_job to separate function Split out the work of creating a new job path in preparation of job mirrors being added --- src/job.rs | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/job.rs b/src/job.rs index 0ab3586..971923b 100644 --- a/src/job.rs +++ b/src/job.rs @@ -15,7 +15,7 @@ use std::os::unix::process::ExitStatusExt; use std::process::ExitStatus; use tokio::process::{Child, Command}; use tracing::error; -use zbus::{fdo, interface, zvariant, Connection, InterfaceRef, SignalContext}; +use zbus::{fdo, interface, zvariant, Connection, Interface, InterfaceRef, SignalContext}; use crate::error::to_zbus_fdo_error; @@ -54,19 +54,9 @@ impl JobManager { }) } - pub async fn run_process( - &mut self, - executable: &str, - args: &[impl AsRef], - operation_name: &str, - ) -> fdo::Result { - // Run the given executable and give back an object path + async fn add_job(&mut self, job: J) -> fdo::Result { let path = format!("{}/{}", JOB_PREFIX, self.next_job); self.next_job += 1; - let job = Job::spawn(executable, args) - .await - .inspect_err(|message| error!("Error {operation_name}: {message}")) - .map_err(to_zbus_fdo_error)?; self.connection .object_server() .at(path.as_str(), job) @@ -77,6 +67,21 @@ impl JobManager { .await?; Ok(object_path) } + + pub async fn run_process( + &mut self, + executable: &str, + args: &[impl AsRef], + operation_name: &str, + ) -> fdo::Result { + // Run the given executable and give back an object path + let job = Job::spawn(executable, args) + .await + .inspect_err(|message| error!("Error {operation_name}: {message}")) + .map_err(to_zbus_fdo_error)?; + + self.add_job(job).await + } } #[interface(name = "com.steampowered.SteamOSManager1.JobManager")]