forked from mtusi2026/mtusi2026lab6
refactor(api): stop running reconciler inside API
This commit is contained in:
@@ -21,10 +21,10 @@ func main() {
|
|||||||
log.Fatalf("reconciler: конфигурация: %v", err)
|
log.Fatalf("reconciler: конфигурация: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !cfg.ReconcilerEnabled {
|
// if !cfg.ReconcilerEnabled {
|
||||||
log.Println("reconciler: RECONCILER_ENABLED=false, выходим")
|
// log.Println("reconciler: RECONCILER_ENABLED=false, выходим")
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
|
|
||||||
if !cfg.S3Configured() {
|
if !cfg.S3Configured() {
|
||||||
log.Fatal("reconciler: S3 не настроен: задайте S3_ENDPOINT, S3_BUCKET, S3_ACCESS_KEY_ID_FILE/S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY_FILE/S3_SECRET_ACCESS_KEY")
|
log.Fatal("reconciler: S3 не настроен: задайте S3_ENDPOINT, S3_BUCKET, S3_ACCESS_KEY_ID_FILE/S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY_FILE/S3_SECRET_ACCESS_KEY")
|
||||||
|
|||||||
+14
-14
@@ -134,21 +134,21 @@ func main() {
|
|||||||
|
|
||||||
srv := &http.Server{Addr: addr, Handler: router}
|
srv := &http.Server{Addr: addr, Handler: router}
|
||||||
|
|
||||||
reconcilerCtx, reconcilerCancel := context.WithCancel(context.Background())
|
// reconcilerCtx, reconcilerCancel := context.WithCancel(context.Background())
|
||||||
defer reconcilerCancel()
|
// defer reconcilerCancel()
|
||||||
if cfg.ReconcilerEnabled {
|
// if cfg.ReconcilerEnabled {
|
||||||
reconciler := service.NewReconciler(
|
// reconciler := service.NewReconciler(
|
||||||
store.Attachments(),
|
// store.Attachments(),
|
||||||
objectStorage,
|
// objectStorage,
|
||||||
store.Outbox(),
|
// store.Outbox(),
|
||||||
pool,
|
// pool,
|
||||||
cfg.ReconcilerGracePeriod,
|
// cfg.ReconcilerGracePeriod,
|
||||||
)
|
// )
|
||||||
go reconciler.Run(reconcilerCtx, cfg.ReconcilerInterval)
|
// go reconciler.Run(reconcilerCtx, cfg.ReconcilerInterval)
|
||||||
}
|
// }
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
log.Printf("Запускаем на %s (SESSION_STORE=%s, RECONCILER_ENABLED=%v)", addr, cfg.SessionStore, cfg.ReconcilerEnabled)
|
log.Printf("Запускаем на %s (SESSION_STORE=%s, RECONCILER_ENABLED=%v)", addr, cfg.SessionStore)
|
||||||
if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||||
log.Fatalf("Ошибка запуска: %v", err)
|
log.Fatalf("Ошибка запуска: %v", err)
|
||||||
}
|
}
|
||||||
@@ -162,7 +162,7 @@ func main() {
|
|||||||
ready.Store(false)
|
ready.Store(false)
|
||||||
|
|
||||||
outboxCancel()
|
outboxCancel()
|
||||||
reconcilerCancel()
|
// reconcilerCancel()
|
||||||
|
|
||||||
if cfg.ShutdownDrain > 0 {
|
if cfg.ShutdownDrain > 0 {
|
||||||
time.Sleep(cfg.ShutdownDrain)
|
time.Sleep(cfg.ShutdownDrain)
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ type Config struct {
|
|||||||
MaxUploadBytes int64
|
MaxUploadBytes int64
|
||||||
MaxImagePixels int64
|
MaxImagePixels int64
|
||||||
|
|
||||||
ReconcilerEnabled bool
|
// ReconcilerEnabled bool
|
||||||
ReconcilerInterval time.Duration
|
ReconcilerInterval time.Duration
|
||||||
ReconcilerGracePeriod time.Duration
|
ReconcilerGracePeriod time.Duration
|
||||||
|
|
||||||
@@ -111,10 +111,10 @@ func Load() (*Config, error) {
|
|||||||
return nil, fmt.Errorf("MAX_IMAGE_PIXELS должен быть положительным")
|
return nil, fmt.Errorf("MAX_IMAGE_PIXELS должен быть положительным")
|
||||||
}
|
}
|
||||||
|
|
||||||
reconcilerEnabled, err := readBool("RECONCILER_ENABLED", true)
|
// reconcilerEnabled, err := readBool("RECONCILER_ENABLED", true)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return nil, fmt.Errorf("RECONCILER_ENABLED: %w", err)
|
// return nil, fmt.Errorf("RECONCILER_ENABLED: %w", err)
|
||||||
}
|
// }
|
||||||
reconcilerIntervalSec, err := readInt("RECONCILER_INTERVAL_SECONDS", 300)
|
reconcilerIntervalSec, err := readInt("RECONCILER_INTERVAL_SECONDS", 300)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("RECONCILER_INTERVAL_SECONDS: %w", err)
|
return nil, fmt.Errorf("RECONCILER_INTERVAL_SECONDS: %w", err)
|
||||||
@@ -160,7 +160,7 @@ func Load() (*Config, error) {
|
|||||||
MaxUploadBytes: maxUploadBytes,
|
MaxUploadBytes: maxUploadBytes,
|
||||||
MaxImagePixels: maxImagePixels,
|
MaxImagePixels: maxImagePixels,
|
||||||
|
|
||||||
ReconcilerEnabled: reconcilerEnabled,
|
// ReconcilerEnabled: reconcilerEnabled,
|
||||||
ReconcilerInterval: time.Duration(reconcilerIntervalSec) * time.Second,
|
ReconcilerInterval: time.Duration(reconcilerIntervalSec) * time.Second,
|
||||||
ReconcilerGracePeriod: time.Duration(reconcilerGraceSec) * time.Second,
|
ReconcilerGracePeriod: time.Duration(reconcilerGraceSec) * time.Second,
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user