Skip to content

Commit

Permalink
ref: More logging for ongoing and get_backup (#4289)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
flub authored Apr 4, 2023
1 parent 185a019 commit 86c18fb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
13 changes: 9 additions & 4 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

Expand All @@ -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.",);
}
}
Expand All @@ -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,
}
}

Expand Down
10 changes: 7 additions & 3 deletions src/imex/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 86c18fb

Please sign in to comment.