Skip to content

Commit 86c18fb

Browse files
authored
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.
1 parent 185a019 commit 86c18fb

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/context.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ enum RunningState {
260260
Running { cancel_sender: Sender<()> },
261261

262262
/// Cancel signal has been sent, waiting for ongoing process to be freed.
263-
ShallStop,
263+
ShallStop { request: Instant },
264264

265265
/// There is no ongoing process, a new one can be allocated.
266266
Stopped,
@@ -530,6 +530,9 @@ impl Context {
530530

531531
pub(crate) async fn free_ongoing(&self) {
532532
let mut s = self.running_state.write().await;
533+
if let RunningState::ShallStop { request } = *s {
534+
info!(self, "Ongoing stopped in {:?}", request.elapsed());
535+
}
533536
*s = RunningState::Stopped;
534537
}
535538

@@ -542,9 +545,11 @@ impl Context {
542545
warn!(self, "could not cancel ongoing: {:#}", err);
543546
}
544547
info!(self, "Signaling the ongoing process to stop ASAP.",);
545-
*s = RunningState::ShallStop;
548+
*s = RunningState::ShallStop {
549+
request: Instant::now(),
550+
};
546551
}
547-
RunningState::ShallStop | RunningState::Stopped => {
552+
RunningState::ShallStop { .. } | RunningState::Stopped => {
548553
info!(self, "No ongoing process to stop.",);
549554
}
550555
}
@@ -554,7 +559,7 @@ impl Context {
554559
pub(crate) async fn shall_stop_ongoing(&self) -> bool {
555560
match &*self.running_state.read().await {
556561
RunningState::Running { .. } => false,
557-
RunningState::ShallStop | RunningState::Stopped => true,
562+
RunningState::ShallStop { .. } | RunningState::Stopped => true,
558563
}
559564
}
560565

src/imex/transfer.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use crate::blob::BlobDirContents;
5050
use crate::chat::{add_device_msg, delete_and_reset_all_device_msgs};
5151
use crate::context::Context;
5252
use crate::message::{Message, Viewtype};
53-
use crate::qr::Qr;
53+
use crate::qr::{self, Qr};
5454
use crate::stock_str::backup_transfer_msg_body;
5555
use crate::{e2ee, EventType};
5656

@@ -393,10 +393,14 @@ pub async fn get_backup(context: &Context, qr: Qr) -> Result<()> {
393393
!context.is_configured().await?,
394394
"Cannot import backups to accounts in use."
395395
);
396-
let _guard = context.scheduler.pause(context.clone()).await;
397-
398396
// Acquire global "ongoing" mutex.
399397
let cancel_token = context.alloc_ongoing().await?;
398+
let _guard = context.scheduler.pause(context.clone()).await;
399+
info!(
400+
context,
401+
"Running get_backup for {}",
402+
qr::format_backup(&qr)?
403+
);
400404
let res = tokio::select! {
401405
biased;
402406
res = get_backup_inner(context, qr) => res,

0 commit comments

Comments
 (0)