diff --git a/svc/product_series_auto_scheduler.go b/svc/product_series_auto_scheduler.go index 45aa158..a05dbea 100644 --- a/svc/product_series_auto_scheduler.go +++ b/svc/product_series_auto_scheduler.go @@ -292,9 +292,12 @@ func startProductSeriesAutoSchedulers(pgDB *sql.DB) { apply := envBool("PRODUCT_SERIES_AUTO_APPLY", false) deltaIntervalMin := envIntRange("PRODUCT_SERIES_DELTA_INTERVAL_MIN", 60, 5, 1440) queueBatch := envIntRange("PRODUCT_SERIES_DELTA_BATCH_SIZE", 300, 10, 2000) - fullHH, fullMM := envHHMM("PRODUCT_SERIES_FULL_HHMM", 5, 30) - runFullOnStartup := envBool("PRODUCT_SERIES_FULL_RUN_ON_STARTUP", false) - runDeltaOnStartup := envBool("PRODUCT_SERIES_DELTA_RUN_ON_STARTUP", false) + fullHH, fullMM := envHHMM("PRODUCT_SERIES_FULL_HHMM", 5, 0) + // Deploys should not trigger heavy jobs. Startup runs are gated behind an extra allow flag so + // a stale/old env var value can't accidentally bring back "runs on every deploy" behavior. + allowStartupRuns := envBool("PRODUCT_SERIES_ALLOW_STARTUP_RUNS", false) + runFullOnStartup := allowStartupRuns && envBool("PRODUCT_SERIES_FULL_RUN_ON_STARTUP", false) + runDeltaOnStartup := allowStartupRuns && envBool("PRODUCT_SERIES_DELTA_RUN_ON_STARTUP", false) var deltaRunning int32 var fullRunning int32 @@ -363,14 +366,14 @@ func startProductSeriesAutoSchedulers(pgDB *sql.DB) { runFull("startup_manual") } for { - next := nextProductSeriesWeeklyRun(time.Now(), fullHH, fullMM) + next := nextProductSeriesDailyRun(time.Now(), fullHH, fullMM) wait := time.Until(next) if wait < 0 { wait = time.Minute } log.Printf("[ProductSeriesFull] scheduled next_at=%s in=%s", next.Format(time.RFC3339), wait.Round(time.Second)) time.Sleep(wait) - runFull("weekly") + runFull("daily") } }() } @@ -1578,15 +1581,13 @@ func nullableInt64ForAuto(v sql.NullInt64) any { return v.Int64 } -func nextProductSeriesWeeklyRun(now time.Time, hh int, mm int) time.Time { +func nextProductSeriesDailyRun(now time.Time, hh int, mm int) time.Time { loc := now.Location() base := time.Date(now.Year(), now.Month(), now.Day(), hh, mm, 0, 0, loc) - daysUntilMon := (int(time.Monday) - int(now.Weekday()) + 7) % 7 - candidate := base.AddDate(0, 0, daysUntilMon) - if !candidate.After(now) { - candidate = candidate.AddDate(0, 0, 7) + if base.After(now) { + return base } - return candidate + return base.AddDate(0, 0, 1) } func envBool(key string, fallback bool) bool {