ref: More logging for ongoing and get_backup (#4289)

This adds a few log items for imex::transfer::get_backup and the
ongoing process to give some more insights.

IO is now also paused after the ongoing process is allocated in
get_backup to avoid needlessly pausing IO.
This commit is contained in:
Floris Bruynooghe
2023-04-04 18:11:45 +02:00
committed by GitHub
parent 185a0193cc
commit 86c18fb3ae
2 changed files with 16 additions and 7 deletions

View File

@@ -260,7 +260,7 @@ enum RunningState {
Running { cancel_sender: Sender<()> },
/// Cancel signal has been sent, waiting for ongoing process to be freed.
ShallStop,
ShallStop { request: Instant },
/// There is no ongoing process, a new one can be allocated.
Stopped,
@@ -530,6 +530,9 @@ impl Context {
pub(crate) async fn free_ongoing(&self) {
let mut s = self.running_state.write().await;
if let RunningState::ShallStop { request } = *s {
info!(self, "Ongoing stopped in {:?}", request.elapsed());
}
*s = RunningState::Stopped;
}
@@ -542,9 +545,11 @@ impl Context {
warn!(self, "could not cancel ongoing: {:#}", err);
}
info!(self, "Signaling the ongoing process to stop ASAP.",);
*s = RunningState::ShallStop;
*s = RunningState::ShallStop {
request: Instant::now(),
};
}
RunningState::ShallStop | RunningState::Stopped => {
RunningState::ShallStop { .. } | RunningState::Stopped => {
info!(self, "No ongoing process to stop.",);
}
}
@@ -554,7 +559,7 @@ impl Context {
pub(crate) async fn shall_stop_ongoing(&self) -> bool {
match &*self.running_state.read().await {
RunningState::Running { .. } => false,
RunningState::ShallStop | RunningState::Stopped => true,
RunningState::ShallStop { .. } | RunningState::Stopped => true,
}
}

View File

@@ -50,7 +50,7 @@ use crate::blob::BlobDirContents;
use crate::chat::{add_device_msg, delete_and_reset_all_device_msgs};
use crate::context::Context;
use crate::message::{Message, Viewtype};
use crate::qr::Qr;
use crate::qr::{self, Qr};
use crate::stock_str::backup_transfer_msg_body;
use crate::{e2ee, EventType};
@@ -393,10 +393,14 @@ pub async fn get_backup(context: &Context, qr: Qr) -> Result<()> {
!context.is_configured().await?,
"Cannot import backups to accounts in use."
);
let _guard = context.scheduler.pause(context.clone()).await;
// Acquire global "ongoing" mutex.
let cancel_token = context.alloc_ongoing().await?;
let _guard = context.scheduler.pause(context.clone()).await;
info!(
context,
"Running get_backup for {}",
qr::format_backup(&qr)?
);
let res = tokio::select! {
biased;
res = get_backup_inner(context, qr) => res,