Add shutdown command to gracefully stop running daemons

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent 3924fd8f45
commit ddde0ea113

@ -1,6 +1,6 @@
[package]
name = "mediarepo-api"
version = "0.24.2"
version = "0.25.0"
edition = "2018"
license = "gpl-3"

@ -111,9 +111,22 @@ impl ApiClient {
Ok(res.payload::<InfoResponse>()?)
}
/// Shuts down the daemon that the client is connected to.
#[tracing::instrument(level = "debug", skip(self))]
pub async fn shutdown_daemon(&self) -> ApiResult<()> {
self.ctx
.acquire()
.emit("shutdown", ())
.await_reply()
.with_timeout(Duration::from_secs(5))
.await?;
Ok(())
}
#[tracing::instrument(level = "debug", skip(self))]
pub async fn exit(self) -> ApiResult<()> {
let ctx = (*self.ctx.acquire()).clone();
ctx.stop().await?;
Ok(())
}

@ -140,6 +140,11 @@ pub async fn close_local_repository(
let mut active_repo = app_state.active_repo.write().await;
if let Some(path) = mem::take(&mut *active_repo).and_then(|r| r.path) {
if let Ok(api) = api_state.api().await {
if let Err(e) = api.shutdown_daemon().await {
tracing::error!("failed to ask the daemon to shut down daemon {:?}", e);
}
}
app_state.stop_running_daemon(&path).await?;
}
api_state.disconnect().await;

Loading…
Cancel
Save