From dfb3503ba31c23ca04f68392f4d0144b1d36e172 Mon Sep 17 00:00:00 2001
From: Neil Schark <neil.schark@h-da.de>
Date: Wed, 6 Mar 2024 10:19:26 +0000
Subject: [PATCH] test retries

---
 controller/eventService/Service.go | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/controller/eventService/Service.go b/controller/eventService/Service.go
index 7c822fc8a..3ab30a428 100644
--- a/controller/eventService/Service.go
+++ b/controller/eventService/Service.go
@@ -80,12 +80,17 @@ func NewEventService() (interfaces.Service, error) {
 }
 
 func connect(addr string) (*amqp.Connection, error) {
-	conn, err := amqp.Dial(addr)
-	if err != nil {
-		return nil, &customerrs.AMQPInitFailError{Action: "failed to connect to RabbitMQ", Err: err}
+	retries := 60
+
+	for i := 0; i < retries; i++ {
+		conn, err := amqp.Dial(addr)
+		if err == nil {
+			return conn, nil
+		}
+		time.Sleep(2 * time.Second)
 	}
 
-	return conn, nil
+	return nil, &customerrs.AMQPInitFailError{Action: "failed to connect to RabbitMQ", Err: err}
 }
 
 // Reconnect attempts to setup a new connection to the RabbitMQ server after an disconnect.
-- 
GitLab