src/server/worker_task.rs: switch to async

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2019-08-27 09:18:39 +02:00
parent aa4110cc64
commit 75fef4b463

View File

@ -96,17 +96,14 @@ pub fn create_task_control_socket() -> Result<(), Error> {
} }
pub fn abort_worker_async(upid: UPID) { pub fn abort_worker_async(upid: UPID) {
let task = abort_worker(upid); tokio::spawn(async move {
if let Err(err) = abort_worker(upid).await {
tokio::spawn(task.then(|res| {
if let Err(err) = res {
eprintln!("abort worker failed - {}", err); eprintln!("abort worker failed - {}", err);
} }
Ok(()) });
}));
} }
pub fn abort_worker(upid: UPID) -> impl Future<Item=(), Error=Error> { pub fn abort_worker(upid: UPID) -> impl Future<Output = Result<(), Error>> {
let target_pid = upid.pid; let target_pid = upid.pid;
@ -118,7 +115,7 @@ pub fn abort_worker(upid: UPID) -> impl Future<Item=(), Error=Error> {
"upid": upid.to_string(), "upid": upid.to_string(),
}); });
super::send_command(socketname, cmd).map(|_| {}) super::send_command(socketname, cmd).map_ok(|_| ())
} }
fn parse_worker_status_line(line: &str) -> Result<(String, UPID, Option<(i64, String)>), Error> { fn parse_worker_status_line(line: &str) -> Result<(String, UPID, Option<(i64, String)>), Error> {
@ -411,15 +408,15 @@ impl WorkerTask {
f: F, f: F,
) -> Result<String, Error> ) -> Result<String, Error>
where F: Send + 'static + FnOnce(Arc<WorkerTask>) -> T, where F: Send + 'static + FnOnce(Arc<WorkerTask>) -> T,
T: Send + 'static + Future<Item=(), Error=Error>, T: Send + 'static + Future<Output = Result<(), Error>>,
{ {
let worker = WorkerTask::new(worker_type, worker_id, username, to_stdout)?; let worker = WorkerTask::new(worker_type, worker_id, username, to_stdout)?;
let upid_str = worker.upid.to_string(); let upid_str = worker.upid.to_string();
let f = f(worker.clone());
tokio::spawn(f(worker.clone()).then(move |result| { tokio::spawn(async move {
let result = f.await;
worker.log_result(&result); worker.log_result(&result);
Ok(()) });
}));
Ok(upid_str) Ok(upid_str)
} }
@ -461,7 +458,7 @@ impl WorkerTask {
p.send(()).unwrap(); p.send(()).unwrap();
}); });
tokio::spawn(c.then(|_| Ok(()))); tokio::spawn(c.map(|_| ()));
Ok(upid_str) Ok(upid_str)
} }