diff --git a/backend/cmd/server/main.go b/backend/cmd/server/main.go index d73e7e9..c0c74af 100644 --- a/backend/cmd/server/main.go +++ b/backend/cmd/server/main.go @@ -78,6 +78,10 @@ func main() { Region: cfg.S3Region, }) if err != nil { + var unavailable *domain.UnavailableError + if errors.As(err, &unavailable) { + log.Fatalf("s3: %v (reason: %s)", err, unavailable.Reason) + } log.Fatalf("s3: %v", err) } @@ -114,8 +118,20 @@ func main() { srv := &http.Server{Addr: addr, Handler: router} + reconcilerCtx, reconcilerCancel := context.WithCancel(context.Background()) + defer reconcilerCancel() + if cfg.ReconcilerEnabled { + reconciler := service.NewReconciler( + store.Attachments(), + objectStorage, + pool, + cfg.ReconcilerGracePeriod, + ) + go reconciler.Run(reconcilerCtx, cfg.ReconcilerInterval) + } + go func() { - log.Printf("Запускаем на %s (SESSION_STORE=%s)", addr, cfg.SessionStore) + log.Printf("Запускаем на %s (SESSION_STORE=%s, RECONCILER_ENABLED=%v)", addr, cfg.SessionStore, cfg.ReconcilerEnabled) if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) { log.Fatalf("Ошибка запуска: %v", err) } @@ -127,6 +143,7 @@ func main() { log.Printf("Получен сигнал завершения; readiness выключен, drain %s", cfg.ShutdownDrain) ready.Store(false) + reconcilerCancel() if cfg.ShutdownDrain > 0 { time.Sleep(cfg.ShutdownDrain) diff --git a/compose.yaml b/compose.yaml index 91a67a5..7d6242c 100644 --- a/compose.yaml +++ b/compose.yaml @@ -163,6 +163,9 @@ services: S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_secret_access_key MAX_UPLOAD_BYTES: "${MAX_UPLOAD_BYTES:-10485760}" MAX_IMAGE_PIXELS: "${MAX_IMAGE_PIXELS:-40000000}" + RECONCILER_ENABLED: "${RECONCILER_ENABLED:-true}" + RECONCILER_INTERVAL_SECONDS: "${RECONCILER_INTERVAL_SECONDS:-300}" + RECONCILER_GRACE_SECONDS: "${RECONCILER_GRACE_SECONDS:-3600}" secrets: - database_url - cache_url