job: Move add_job to separate function

Split out the work of creating a new job path in preparation of job mirrors
being added
This commit is contained in:
Vicki Pfau 2024-07-17 20:26:16 -07:00
parent 8e3fc1afeb
commit ae2351594f

View file

@ -15,7 +15,7 @@ use std::os::unix::process::ExitStatusExt;
use std::process::ExitStatus; use std::process::ExitStatus;
use tokio::process::{Child, Command}; use tokio::process::{Child, Command};
use tracing::error; 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; use crate::error::to_zbus_fdo_error;
@ -54,19 +54,9 @@ impl JobManager {
}) })
} }
pub async fn run_process( async fn add_job<J: Interface>(&mut self, job: J) -> fdo::Result<zvariant::OwnedObjectPath> {
&mut self,
executable: &str,
args: &[impl AsRef<OsStr>],
operation_name: &str,
) -> fdo::Result<zvariant::OwnedObjectPath> {
// Run the given executable and give back an object path
let path = format!("{}/{}", JOB_PREFIX, self.next_job); let path = format!("{}/{}", JOB_PREFIX, self.next_job);
self.next_job += 1; 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 self.connection
.object_server() .object_server()
.at(path.as_str(), job) .at(path.as_str(), job)
@ -77,6 +67,21 @@ impl JobManager {
.await?; .await?;
Ok(object_path) Ok(object_path)
} }
pub async fn run_process(
&mut self,
executable: &str,
args: &[impl AsRef<OsStr>],
operation_name: &str,
) -> fdo::Result<zvariant::OwnedObjectPath> {
// 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")] #[interface(name = "com.steampowered.SteamOSManager1.JobManager")]