private async Task ApplyUpdates(DiffObject updates)
        {
            try
            {
                var sw = new Stopwatch();
                sw.Start();
                var retries = await Context.PersistenceManager.ApplyUpdates(updates);

                sw.Stop();

                var batchInfo = new BatchSavedInfo
                {
                    SavedAt             = DateTime.UtcNow,
                    QuantaCount         = updates.Quanta.Count,
                    EffectsCount        = updates.EffectsCount,
                    ElapsedMilliseconds = sw.ElapsedMilliseconds,
                    Retries             = retries
                };
                _ = Task.Factory.StartNew(() => OnBatchSaved?.Invoke(batchInfo));
            }
            catch (Exception exc)
            {
                //we need to cancel all pending updates
                cancellationTokenSource.Cancel();
                if (Context.AppState.State != ApplicationState.Failed)
                {
                    OnSaveFailed("Error on saving updates.", exc);
                }
            }
        }
Exemplo n.º 2
0
 public void OnBatchSaved(BatchSavedInfo batchInfo)
 {
     lock (syncRoot)
     {
         LastBatchInfos.Add(batchInfo);
         if (LastBatchInfos.Count > 20)
         {
             LastBatchInfos.RemoveAt(0);
         }
     }
 }
        private void PendingUpdatesManager_OnBatchSaved(BatchSavedInfo batchInfo)
        {
            var message = $"Batch saved on the {batchInfo.Retries} try. Quanta count: {batchInfo.QuantaCount}; effects count: {batchInfo.EffectsCount}.";

            if (batchInfo.Retries > 1)
            {
                logger.Warn(message);
            }
            else
            {
                logger.Trace(message);
            }
            PerformanceStatisticsManager?.OnBatchSaved(batchInfo);
        }
Exemplo n.º 4
0
        public static Models.BatchSavedInfo ToBatchSavedInfoModel(this BatchSavedInfo batchSavedInfo)
        {
            if (batchSavedInfo == null)
            {
                throw new ArgumentNullException(nameof(batchSavedInfo));
            }

            return(new Models.BatchSavedInfo
            {
                EffectsCount = batchSavedInfo.EffectsCount,
                QuantaCount = batchSavedInfo.QuantaCount,
                ElapsedMilliseconds = batchSavedInfo.ElapsedMilliseconds,
                Retries = batchSavedInfo.Retries,
                SavedAt = batchSavedInfo.SavedAt.Ticks
            });
        }