Skip to content

Commit

Permalink
fix compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
chliddle committed Dec 10, 2024
1 parent 2e8ea4b commit 5d9acdd
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions orm/src/migrations.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use deadpool_diesel::postgres::Object;
use deadpool_diesel::InteractError;
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
use std::time::Duration;
use tokio::time::sleep;
use diesel::prelude::*; // Add this for RunQueryDsl
use diesel::sql_types::Bool; // Add this for the SQL query type
use diesel_migrations::{
embed_migrations, EmbeddedMigrations, MigrationHarness,
};
use std::{thread, time::Duration}; // Use thread::sleep instead of tokio::sleep

pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!("migrations");

Expand All @@ -13,9 +16,9 @@ pub async fn run_migrations(conn: &Object) -> Result<(), InteractError> {
while attempt < max_retries {
let result = conn.interact(|transaction_conn| {
// Try to acquire an advisory lock
let lock_result: Result<bool, _> = diesel::sql_query("SELECT pg_try_advisory_lock(1)")
.get_result(transaction_conn)
.map(|row: (bool,)| row.0);
let lock_result: QueryResult<bool> = diesel::sql_query("SELECT pg_try_advisory_lock(1)")
.get_result::<(bool,)>(transaction_conn)
.map(|row| row.0);

match lock_result {
Ok(true) => {
Expand Down Expand Up @@ -48,13 +51,16 @@ pub async fn run_migrations(conn: &Object) -> Result<(), InteractError> {
// For other errors, retry after delay
attempt += 1;
if attempt < max_retries {
sleep(Duration::from_secs(1 << attempt)).await; // Exponential backoff
thread::sleep(Duration::from_secs(1 << attempt)); // Use thread::sleep
continue;
}
return Err(e);
}
}
}

Err(InteractError::Message("Max retries exceeded".into()))
Err(InteractError::Error(Box::new(std::io::Error::new( // Fixed error creation
std::io::ErrorKind::Other,
"Max retries exceeded"
))))
}

0 comments on commit 5d9acdd

Please sign in to comment.