diff --git a/Cargo.lock b/Cargo.lock
index ac64a597..212f8687 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4141,6 +4141,7 @@ dependencies = [
[[package]]
name = "relayer-utils"
version = "0.3.7"
+source = "git+https://github.com/zkemail/relayer-utils.git?rev=94d78d6#94d78d67862b6d6c15bebac66d184c7557f6aff5"
dependencies = [
"anyhow",
"base64 0.21.7",
diff --git a/packages/relayer/src/database.rs b/packages/relayer/src/database.rs
index 5dd0fbb9..5ee0e8d2 100644
--- a/packages/relayer/src/database.rs
+++ b/packages/relayer/src/database.rs
@@ -73,6 +73,31 @@ impl Database {
Ok(())
}
+ // This is a hacky way to make all subsequent uses of "pub static ref DB" work
+ // Since the DB ref will only be connected to the database after it was used once
+ // -> The first request always times out
+ pub(crate) async fn initialize_db_connection(&self) -> Result<()> {
+ // Try up to 3 times
+ for i in 1..4 {
+ match sqlx::query("SELECT 1").execute(&self.db).await {
+ Ok(_) => {
+ info!(LOG, "Connected successfully to database");
+ return Ok(());
+ }
+ Err(e) => {
+ error!(
+ LOG,
+ "Failed to initialize connection to the database: {:?}. Retrying...", e
+ );
+ tokio::time::sleep(Duration::from_secs(i * i)).await;
+ }
+ }
+ }
+ Err(anyhow::anyhow!(
+ "Failed to initialize database connection after 3 attempts"
+ ))
+ }
+
pub(crate) async fn get_credentials(&self, account_code: &str) -> Result