Skip to content

Commit

Permalink
graceful close on shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
segfault-magnet committed May 2, 2024
1 parent 12943a0 commit 2bde4bf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/adapters/storage/postgresql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ impl Postgres {
Ok(Self { connection_pool })
}

/// Close only when shutting down the application. Will close the connection pool even if it is
/// shared.
pub async fn close(self) {
self.connection_pool.close().await;
}

pub async fn migrate(&self) -> Result<()> {
sqlx::migrate!().run(&self.connection_pool).await?;
Ok(())
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async fn main() -> Result<()> {
launch_api_server(
&config,
metrics_registry,
storage,
storage.clone(),
fuel_health_check,
eth_health_check,
)
Expand All @@ -74,6 +74,7 @@ async fn main() -> Result<()> {
wallet_balance_tracker_handle,
committer_handle,
listener_handle,
storage,
)
.await
}
Expand Down
2 changes: 2 additions & 0 deletions src/setup/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ pub async fn shut_down(
wallet_balance_tracker_handle: JoinHandle<()>,
committer_handle: JoinHandle<()>,
listener_handle: JoinHandle<()>,
storage: Postgres,
) -> Result<()> {
cancel_token.cancel();

Expand All @@ -213,5 +214,6 @@ pub async fn shut_down(
handle.await?;
}

storage.close().await;
Ok(())
}

0 comments on commit 2bde4bf

Please sign in to comment.