ui: add B2B olmayan stok (orphans) page
This commit is contained in:
@@ -292,9 +292,12 @@ func startProductSeriesAutoSchedulers(pgDB *sql.DB) {
|
|||||||
apply := envBool("PRODUCT_SERIES_AUTO_APPLY", false)
|
apply := envBool("PRODUCT_SERIES_AUTO_APPLY", false)
|
||||||
deltaIntervalMin := envIntRange("PRODUCT_SERIES_DELTA_INTERVAL_MIN", 60, 5, 1440)
|
deltaIntervalMin := envIntRange("PRODUCT_SERIES_DELTA_INTERVAL_MIN", 60, 5, 1440)
|
||||||
queueBatch := envIntRange("PRODUCT_SERIES_DELTA_BATCH_SIZE", 300, 10, 2000)
|
queueBatch := envIntRange("PRODUCT_SERIES_DELTA_BATCH_SIZE", 300, 10, 2000)
|
||||||
fullHH, fullMM := envHHMM("PRODUCT_SERIES_FULL_HHMM", 5, 30)
|
fullHH, fullMM := envHHMM("PRODUCT_SERIES_FULL_HHMM", 5, 0)
|
||||||
runFullOnStartup := envBool("PRODUCT_SERIES_FULL_RUN_ON_STARTUP", false)
|
// Deploys should not trigger heavy jobs. Startup runs are gated behind an extra allow flag so
|
||||||
runDeltaOnStartup := envBool("PRODUCT_SERIES_DELTA_RUN_ON_STARTUP", false)
|
// 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 deltaRunning int32
|
||||||
var fullRunning int32
|
var fullRunning int32
|
||||||
@@ -363,14 +366,14 @@ func startProductSeriesAutoSchedulers(pgDB *sql.DB) {
|
|||||||
runFull("startup_manual")
|
runFull("startup_manual")
|
||||||
}
|
}
|
||||||
for {
|
for {
|
||||||
next := nextProductSeriesWeeklyRun(time.Now(), fullHH, fullMM)
|
next := nextProductSeriesDailyRun(time.Now(), fullHH, fullMM)
|
||||||
wait := time.Until(next)
|
wait := time.Until(next)
|
||||||
if wait < 0 {
|
if wait < 0 {
|
||||||
wait = time.Minute
|
wait = time.Minute
|
||||||
}
|
}
|
||||||
log.Printf("[ProductSeriesFull] scheduled next_at=%s in=%s", next.Format(time.RFC3339), wait.Round(time.Second))
|
log.Printf("[ProductSeriesFull] scheduled next_at=%s in=%s", next.Format(time.RFC3339), wait.Round(time.Second))
|
||||||
time.Sleep(wait)
|
time.Sleep(wait)
|
||||||
runFull("weekly")
|
runFull("daily")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
@@ -1578,15 +1581,13 @@ func nullableInt64ForAuto(v sql.NullInt64) any {
|
|||||||
return v.Int64
|
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()
|
loc := now.Location()
|
||||||
base := time.Date(now.Year(), now.Month(), now.Day(), hh, mm, 0, 0, loc)
|
base := time.Date(now.Year(), now.Month(), now.Day(), hh, mm, 0, 0, loc)
|
||||||
daysUntilMon := (int(time.Monday) - int(now.Weekday()) + 7) % 7
|
if base.After(now) {
|
||||||
candidate := base.AddDate(0, 0, daysUntilMon)
|
return base
|
||||||
if !candidate.After(now) {
|
|
||||||
candidate = candidate.AddDate(0, 0, 7)
|
|
||||||
}
|
}
|
||||||
return candidate
|
return base.AddDate(0, 0, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func envBool(key string, fallback bool) bool {
|
func envBool(key string, fallback bool) bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user