mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-14 02:11:54 -04:00
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:
parent
8e3fc1afeb
commit
ae2351594f
1 changed files with 17 additions and 12 deletions
29
src/job.rs
29
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<OsStr>],
|
||||
operation_name: &str,
|
||||
) -> fdo::Result<zvariant::OwnedObjectPath> {
|
||||
// Run the given executable and give back an object path
|
||||
async fn add_job<J: Interface>(&mut self, job: J) -> fdo::Result<zvariant::OwnedObjectPath> {
|
||||
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<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")]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue