Improve startup resilience and add debug logging

- Reduce database retry count and backoff time
- Make SECRET_KEY optional (use default with warning)
- Add config debug logging on startup
- Remove strict validation that prevented startup

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Trey t
2025-11-26 20:19:06 -06:00
parent 8feb308f94
commit c319719535
2 changed files with 14 additions and 11 deletions

View File

@@ -33,17 +33,22 @@ func main() {
log.Info().
Bool("debug", cfg.Server.Debug).
Int("port", cfg.Server.Port).
Str("db_host", cfg.Database.Host).
Int("db_port", cfg.Database.Port).
Str("db_name", cfg.Database.Database).
Str("db_user", cfg.Database.User).
Str("redis_url", cfg.Redis.URL).
Msg("Starting MyCrib API server")
// Connect to database (retry with backoff)
// Connect to database (retry with shorter backoff for container health checks)
var db *gorm.DB
for i := 0; i < 5; i++ {
for i := 0; i < 3; i++ {
db, err = database.Connect(&cfg.Database, cfg.Server.Debug)
if err == nil {
break
}
log.Warn().Err(err).Int("attempt", i+1).Msg("Failed to connect to database, retrying...")
time.Sleep(time.Duration(i+1) * 2 * time.Second)
time.Sleep(time.Duration(i+1) * time.Second)
}
if err != nil {
log.Fatal().Err(err).Msg("Failed to connect to database after retries")