Skip to content
This repository was archived by the owner on Sep 8, 2019. It is now read-only.

Commit 12d5160

Browse files
Retry connecting to the database if it fails
Allows starting the docker stack be independant of container start order
1 parent 8d718bf commit 12d5160

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

backend/src/main.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::env;
22
use std::sync::Mutex;
3+
use std::thread;
4+
use std::time;
35

46
use log::debug;
57
use log::error;
@@ -36,11 +38,14 @@ fn main() {
3638

3739
debug!("Connecting to {}", database_url);
3840

39-
let connection = match MysqlConnection::establish(&database_url) {
40-
Ok(c) => c,
41-
Err(e) => {
42-
error!("Could not connect to database: {}", e);
43-
return;
41+
let connection = loop {
42+
match MysqlConnection::establish(&database_url) {
43+
Ok(c) => break c,
44+
Err(e) => {
45+
error!("Could not connect to database: {}", e);
46+
error!("Retrying in a second");
47+
thread::sleep(time::Duration::from_secs(1));
48+
}
4449
}
4550
};
4651

0 commit comments

Comments
 (0)