From c32d25ec28adafec90c43eb19dc0ecd635f4b746 Mon Sep 17 00:00:00 2001 From: notgne2 Date: Fri, 29 Jan 2021 04:13:00 -0700 Subject: Use oneshot signals to ensure SSH activate command has finished before deployment ends --- src/deploy.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/deploy.rs b/src/deploy.rs index 88becc0..00c97f4 100644 --- a/src/deploy.rs +++ b/src/deploy.rs @@ -246,20 +246,25 @@ pub async fn deploy_profile( ssh_wait_command.arg(ssh_opt); } - tokio::pin! { - let ssh_wait_future = ssh_wait_command.arg(self_wait_command).status(); - let ssh_activate_future = ssh_activate.wait_with_output(); - } + let (send_activate, recv_activate) = tokio::sync::oneshot::channel(); + let (send_activated, recv_activated) = tokio::sync::oneshot::channel(); + + tokio::spawn(async move { + send_activate + .send(ssh_activate.wait_with_output().await) + .unwrap(); + send_activated.send(()).unwrap(); + }); tokio::select! { - x = ssh_wait_future => { + x = ssh_wait_command.arg(self_wait_command).status() => { match x.map_err(DeployProfileError::SSHWaitError)?.code() { Some(0) => (), a => return Err(DeployProfileError::SSHWaitExitError(a)), }; }, - x = ssh_activate_future => { - match x.map_err(DeployProfileError::SSHActivateError)?.status.code() { + x = recv_activate => { + match x.unwrap().map_err(DeployProfileError::SSHActivateError)?.status.code() { Some(0) => (), a => return Err(DeployProfileError::SSHActivateExitError(a)), }; @@ -300,6 +305,8 @@ pub async fn deploy_profile( }; info!("Deployment confirmed."); + + recv_activated.await.unwrap(); } Ok(()) -- cgit v1.2.3