@@ -15,7 +15,9 @@ use crate::pg::utils::on_slow;
15
15
use crate :: pg:: PgResult ;
16
16
use crate :: source:: TileInfoSources ;
17
17
use crate :: utils:: { IdResolver , OptBoolObj , OptOneMany } ;
18
- use crate :: MartinResult ;
18
+ use crate :: { MartinError , MartinResult } ;
19
+ use tokio_retry:: strategy:: { jitter, FixedInterval } ;
20
+ use tokio_retry:: Retry ;
19
21
20
22
pub trait PgInfo {
21
23
fn format_id ( & self ) -> String ;
@@ -114,7 +116,18 @@ impl PgConfig {
114
116
}
115
117
116
118
pub async fn resolve ( & mut self , id_resolver : IdResolver ) -> MartinResult < TileInfoSources > {
117
- let pg = PgBuilder :: new ( self , id_resolver) . await ?;
119
+ // Retry strategy: Fixed 5 seconds interval backoff with jitter (random variation)
120
+ let retry_strategy = FixedInterval :: from_millis ( 5000 )
121
+ . map ( jitter) // Add random jitter to avoid "thundering herd" problem
122
+ . take ( 3 ) ; // Retry up to 3 times
123
+
124
+ // Create PgBuilder using retry_strategy
125
+ let pg = Retry :: spawn ( retry_strategy, || async {
126
+ PgBuilder :: new ( self , id_resolver. clone ( ) ) . await
127
+ } )
128
+ . await
129
+ . map_err ( |e| MartinError :: PostgresError ( e) ) ?;
130
+
118
131
let inst_tables = on_slow (
119
132
pg. instantiate_tables ( ) ,
120
133
// warn only if default bounds timeout has already passed
0 commit comments