Skip to content

Commit 0385954

Browse files
feat: add wait for databases to start on Chat and Matching services
1 parent 1041c1a commit 0385954

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

server/chat/src/main/java/meet_at_mensa/chat/ChatApplication.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
55
import org.springframework.web.bind.annotation.GetMapping;
66
import org.springframework.web.bind.annotation.RestController;
7+
import java.util.concurrent.TimeUnit;
78

89
@SpringBootApplication
910
// ChatApplication is the main class for the chat application
@@ -12,9 +13,31 @@ public class ChatApplication {
1213
// The main method is the entry point of the chat service
1314
// It starts the Spring Boot application
1415
public static void main(String[] args) {
16+
17+
wait_for_database_startup();
18+
1519
SpringApplication.run(ChatApplication.class, args);
1620
}
1721

22+
// Wait 30s to ensure that databases have started
23+
private static void wait_for_database_startup() {
24+
25+
System.out.println("Waiting for databases to start...");
26+
27+
try {
28+
29+
TimeUnit.SECONDS.sleep(30);
30+
31+
} catch (InterruptedException e) {
32+
33+
Thread.currentThread().interrupt();
34+
System.out.println("Wait was interrupted");
35+
36+
}
37+
38+
System.out.println("Done waiting for databases to start");
39+
}
40+
1841
@RestController
1942
// HelloController is a REST controller that handles HTTP GET requests
2043
// It returns a greeting message in plain text

server/matching/src/main/java/meet_at_mensa/matching/MatchingApplication.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
55
import org.springframework.web.bind.annotation.GetMapping;
66
import org.springframework.web.bind.annotation.RestController;
7+
import java.util.concurrent.TimeUnit;
78

89
@SpringBootApplication
910
// MatchingApplication is the main class for the matching application
@@ -12,9 +13,31 @@ public class MatchingApplication {
1213
// The main method is the entry point of the matching service
1314
// It starts the Spring Boot application
1415
public static void main(String[] args) {
16+
17+
wait_for_database_startup();
18+
1519
SpringApplication.run(MatchingApplication.class, args);
1620
}
1721

22+
// Wait 30s to ensure that databases have started
23+
private static void wait_for_database_startup() {
24+
25+
System.out.println("Waiting for databases to start...");
26+
27+
try {
28+
29+
TimeUnit.SECONDS.sleep(30);
30+
31+
} catch (InterruptedException e) {
32+
33+
Thread.currentThread().interrupt();
34+
System.out.println("Wait was interrupted");
35+
36+
}
37+
38+
System.out.println("Done waiting for databases to start");
39+
}
40+
1841
@RestController
1942
// HelloController is a REST controller that handles HTTP GET requests
2043
// It returns a greeting message in plain text

server/user/src/main/java/meet_at_mensa/user/UserApplication.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ public static void main(String[] args) {
1919
SpringApplication.run(UserApplication.class, args);
2020
}
2121

22-
// Wait 20s to ensure that databases have started
22+
// Wait 30s to ensure that databases have started
2323
private static void wait_for_database_startup() {
2424

2525
System.out.println("Waiting for databases to start...");
2626

2727
try {
2828

29-
TimeUnit.SECONDS.sleep(20);
29+
TimeUnit.SECONDS.sleep(30);
3030

3131
} catch (InterruptedException e) {
3232

3333
Thread.currentThread().interrupt();
3434
System.out.println("Wait was interrupted");
35-
35+
3636
}
3737

3838
System.out.println("Done waiting for databases to start");

0 commit comments

Comments
 (0)