コード例 #1
0
 public static void SetTimer(UpdateBrotliParam p_state)
 {
     if (g_updateTimer == null)
     {
         g_updateTimer = new System.Threading.Timer(new TimerCallback(Timer_Elapsed), p_state, TimeSpan.FromMilliseconds(10 * 1000), TimeSpan.FromMilliseconds(-1.0));    // first time: start almost immediately
     }
     else
     {
         DateTime etNow        = Utils.ConvertTimeFromUtcToEt(DateTime.UtcNow);
         DateTime targetTimeEt = etNow.AddHours(3);                                   // Polling for change in every 3 hours
         Utils.Logger.Info($"UpdateRedisBrotlisService next targetdate: {targetTimeEt.ToSqDateTimeStr()} ET");
         g_updateTimer.Change(targetTimeEt - etNow, TimeSpan.FromMilliseconds(-1.0)); // runs only once
     }
 }
コード例 #2
0
        public static void Update(UpdateBrotliParam p_state)
        {
            // 1. Check if binary BrotliRecords in RedisDb is Consistent With the text Json source (Json in either in RedisDb, but more likely in PostgreSql)
            // start using Redis:'allAssets.brotli' (520bytes instead of 1.52KB) immediately. User only modifies the JSON version Redis:'allAssets'.
            // 15 seconds later check the Redis consistency. In a very rare case when that finds discrepancy between 'allAssets.brotli' vs. 'allAssets' then
            // it updates Redis:'allAssets.brotli' and re-call HistoricalDataReloadAndSetTimer()

            Utils.Logger.Info($"UpdateRedisBrotlisService.Update()");
            bool wasAnyBrotliUpdated = p_state.Db !.UpdateBrotlisIfNeeded();

            if (wasAnyBrotliUpdated)
            {
                Utils.Logger.Info($"Some Brotlis were updated in RedisDb.");
            }

            // if any brotli was updated, do NOT invoke Reload. It is not the task of this service.
            // ReloadDbDataIfChangedAndSetTimer();
        }