Skip to content

Commit

Permalink
Add storage stop logs
Browse files Browse the repository at this point in the history
  • Loading branch information
jjyr committed Dec 12, 2024
1 parent cf5a520 commit f6a6dab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
16 changes: 7 additions & 9 deletions mutiny-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1625,15 +1625,15 @@ impl<S: MutinyStorage> MutinyWallet<S> {
/// Stops all of the nodes and background processes.
/// Returns after node has been stopped.
pub async fn stop(&mut self) -> Result<(), MutinyError> {
log_trace!(self.logger, "calling stop");
log_debug!(self.logger, "calling stop");

let node_manager = self.node_manager.take().ok_or(MutinyError::NotRunning)?;

node_manager.stop().await?;

// store wallet
{
log_trace!(self.logger, "save wallet state");
log_debug!(self.logger, "save wallet state");
let mut wallet = node_manager
.wallet
.wallet
Expand All @@ -1644,22 +1644,20 @@ impl<S: MutinyStorage> MutinyWallet<S> {
}
}

log_trace!(self.logger, "release device lock");
log_debug!(self.logger, "release device lock");
// stop device lock
self.device_lock_stop_handle.stop().await;

log_trace!(self.logger, "stop logger");
log_debug!(self.logger, "stop logger");
// stop logger
self.logger.stop().await;

// stop the indexeddb object to close db connection
if self.storage.connected().unwrap_or(false) {
log_debug!(self.logger, "stopping storage");
self.storage.stop().await;
log_debug!(self.logger, "stopped storage");
}

log_trace!(self.logger, "finished calling stop");
log_debug!(self.logger, "finished calling stop");
Ok(())
}

Expand Down Expand Up @@ -1728,15 +1726,15 @@ impl<S: MutinyStorage> MutinyWallet<S> {

/// Deletes all the storage
pub async fn delete_all(&self) -> Result<(), MutinyError> {
log_trace!(self.logger, "calling delete_all");
log_debug!(self.logger, "calling delete_all");
if self.node_manager.is_some() {
return Err(MutinyError::AlreadyRunning);
}

self.storage.stop().await;

self.storage.delete_all().await?;
log_trace!(self.logger, "finished calling delete_all");
log_debug!(self.logger, "finished calling delete_all");

Ok(())
}
Expand Down
4 changes: 4 additions & 0 deletions mutiny-wasm/src/indexed_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@ impl MutinyStorage for IndexedDbStorage {
}

async fn start(&mut self) -> Result<(), MutinyError> {
log_debug!(self.logger, "starting storage");
let indexed_db = if self.indexed_db.try_read()?.0.is_none() {
Arc::new(RwLock::new(RexieContainer(Some(
Self::build_indexed_db_database().await?,
Expand All @@ -797,6 +798,7 @@ impl MutinyStorage for IndexedDbStorage {
let memory = Arc::new(RwLock::new(map));
self.indexed_db = indexed_db;
self.memory = memory;
log_debug!(self.logger, "started storage");
Ok(())
}

Expand All @@ -816,6 +818,7 @@ impl MutinyStorage for IndexedDbStorage {
}

async fn stop(&self) {
log_debug!(self.logger, "stopping storage");
// Wait all back ground tasks
self.tasks.wait().await;

Expand All @@ -825,6 +828,7 @@ impl MutinyStorage for IndexedDbStorage {
indexed_db.close();
}
}
log_debug!(self.logger, "stopped storage");
}

fn connected(&self) -> Result<bool, MutinyError> {
Expand Down

0 comments on commit f6a6dab

Please sign in to comment.