From 2691a48e4340f29934a372143faad56ff3512664 Mon Sep 17 00:00:00 2001 From: Richard Holzeis Date: Mon, 22 Jan 2024 10:47:02 +0100 Subject: [PATCH] fix: Run all of the db backup in a dedicated thread Without that fix the open and close position protocol was affected by the db backup to finish. That could lead to the trade dialog not showing a success message. Co-authored-by: Lucas Soriano --- mobile/native/src/backup.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mobile/native/src/backup.rs b/mobile/native/src/backup.rs index 8d0957b2a..c787c68b8 100644 --- a/mobile/native/src/backup.rs +++ b/mobile/native/src/backup.rs @@ -20,7 +20,6 @@ use std::fs; use std::path::Path; use std::sync::Arc; use std::time::Duration; -use tokio::task::spawn_blocking; const BLACKLIST: [&str; 1] = ["ln/network_graph"]; @@ -40,15 +39,18 @@ impl DBBackupSubscriber { } pub fn back_up(&self) -> Result<()> { - let db_backup = db::back_up()?; - tracing::debug!("Successfully created backup of database! Uploading snapshot!"); - let value = fs::read(db_backup)?; - spawn_blocking({ + let runtime = crate::state::get_or_create_tokio_runtime()?; + runtime.spawn_blocking({ let client = self.client.clone(); move || { + let db_backup = db::back_up()?; + tracing::debug!("Successfully created backup of database! Uploading snapshot!"); + let value = fs::read(db_backup)?; client .backup(format!("{DB_BACKUP_KEY}/{DB_BACKUP_NAME}"), value) - .forget() + .forget(); + + anyhow::Ok(()) } });