| 
					
				 | 
			
			
				@@ -5,6 +5,7 @@ import ( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	"log" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	"net/http" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	"os" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	"time" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	"github.com/gorilla/handlers" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	"github.com/jinzhu/gorm" 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -15,6 +16,11 @@ import ( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	"gogs.carducci-dante.gov.it/karmen/core/renderer" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+const ( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	MaxNumRetries     = 20 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	RetryTimeInterval = 2 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 func regenerateRelations(db *gorm.DB) error { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	var activities []orm.Activity 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -39,17 +45,33 @@ func regenerateRelations(db *gorm.DB) error { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 func main() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	var ( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		db  *gorm.DB 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		err error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	log.Println("Loading config file...") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	err := config.ReadFile("config/config.yaml", config.Config) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	err = config.ReadFile("config/config.yaml", config.Config) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		panic(err) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	log.Println("Starting karmen...") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	log.Println("Starting karmen and waiting for the DB...") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	db, err := orm.New(fmt.Sprintf("%s?%s", config.Config.Orm.Connection, config.Config.Orm.Options)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		panic(err) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	count := MaxNumRetries 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	wait := true 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	for wait && count > 0 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		db, err = orm.New(fmt.Sprintf("%s?%s", config.Config.Orm.Connection, config.Config.Orm.Options)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			count-- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			log.Println(err) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			log.Printf("Remaining retries: %d", count) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			time.Sleep(time.Second * RetryTimeInterval) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			continue 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		wait = false 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	orm.Use(db) 
			 |