From dbc0e68fb0e94ef5e7ed12fbc0686fe9afe4a7cb Mon Sep 17 00:00:00 2001 From: Pratham-Mishra04 Date: Wed, 3 Jun 2026 17:12:35 +0530 Subject: [PATCH] fix: pricing tick miss fixes --- framework/modelcatalog/config.go | 5 +++-- framework/modelcatalog/sync.go | 17 +++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/framework/modelcatalog/config.go b/framework/modelcatalog/config.go index be0bd30fc71..80563eb1e00 100644 --- a/framework/modelcatalog/config.go +++ b/framework/modelcatalog/config.go @@ -11,8 +11,9 @@ const ( // syncWorkerTickerPeriod is the fixed interval at which the background sync worker // wakes up to check whether a sync is due. This is independent of pricingSyncInterval — // the ticker defines the check granularity, not the sync frequency. - // Setting pricingSyncInterval below this value has no effect on actual sync frequency. - syncWorkerTickerPeriod = 1 * time.Hour + // Kept well below MinimumPricingSyncIntervalSec so the threshold check is not + // defeated by ticker drift when pricingSyncInterval is set near the minimum. + syncWorkerTickerPeriod = 5 * time.Minute ConfigLastPricingSyncKey = "LastModelPricingSync" ConfigLastParamsSyncKey = "LastModelParametersSync" diff --git a/framework/modelcatalog/sync.go b/framework/modelcatalog/sync.go index 4c1feaeffc0..4140170b056 100644 --- a/framework/modelcatalog/sync.go +++ b/framework/modelcatalog/sync.go @@ -234,19 +234,16 @@ func (mc *ModelCatalog) loadModelParametersFromDatabase(ctx context.Context) (in func (mc *ModelCatalog) startSyncWorker(ctx context.Context) { // IMPORTANT: scheduling model // - // The sync worker wakes on a fixed ticker (syncWorkerTickerPeriod = 1h). - // On each wake it calls checkAndSyncPricing, which checks: + // The sync worker wakes on a fixed ticker (syncWorkerTickerPeriod). On each + // wake it checks: // // time.Since(lastSyncTimestamp) >= pricingSyncInterval // - // This means: - // • pricingSyncInterval defines the *minimum elapsed time* between syncs. - // • The actual sync frequency = max(syncWorkerTickerPeriod, pricingSyncInterval). - // • Setting pricingSyncInterval < 1h does NOT increase sync frequency — - // the hourly ticker is the hard lower bound on check granularity. - // - // Design rationale: avoids high-frequency polling while allowing operators to - // tune how stale pricing data can get (e.g., 1h vs 24h vs 7d). + // pricingSyncInterval defines the minimum elapsed time between syncs. The + // ticker period is the check granularity and must stay well below the + // minimum supported pricingSyncInterval, otherwise ticker drift (the few + // seconds a sync takes to complete) pushes the next check just under the + // threshold and the effective cadence doubles. mc.syncTicker = time.NewTicker(syncWorkerTickerPeriod) mc.wg.Add(1) go mc.syncWorker(ctx)