Esempio n. 1
0
        private static async Task StartPurge()
        {
            using ILifetimeScope scope = _container.BeginLifetimeScope();
            SettingsFactory settingsFactory = scope.Resolve <SettingsFactory>();
            ITraceService   traceService    = scope.Resolve <ITraceService>();

            await WriteTrace(traceService, settingsFactory, "Start Purge");
            await InitializeWorkers();

            CoreSettings        settings      = settingsFactory.CreateCore(_settings);
            IPurgeWorkerFactory workerFactory = scope.Resolve <IPurgeWorkerFactory>();
            IPurgeWorkerSaver   workerSaver   = scope.Resolve <IPurgeWorkerSaver>();
            Guid?workerId = await workerFactory.Claim(settings);

            while (workerId.HasValue && !workerId.Value.Equals(Guid.Empty))
            {
                await WriteTrace(traceService, settingsFactory, $"Claimed worker {workerId.Value}");

                IPurgeWorker purgeWorker = await workerFactory.Get(settings, workerId.Value);

                try
                {
                    await Purge(purgeWorker);
                }
                catch (System.Exception ex)
                {
                    purgeWorker.Status = PurgeWorkerStatus.Error;
                    try
                    {
                        await scope.Resolve <IExceptionService>().Create(settingsFactory.CreateLog(_settings), _settings.ExceptionLoggingDomainId, ex);
                    }
                    catch { }
                    throw;
                }
                finally
                {
                    await workerSaver.Update(settings, purgeWorker);
                    await WriteTrace(traceService, settingsFactory, $"Updated Worker {workerId.Value} Status {purgeWorker.Status}");
                }
                workerId = await workerFactory.Claim(settings);
            }
            try
            {
                await WriteTrace(traceService, settingsFactory, "Purging meta data");
                await PurgMetaData(settingsFactory, scope.Resolve <IPurgeSaver>());
            }
            catch (System.Exception ex)
            {
                Console.Error.WriteLine(ex.ToString());
                try
                {
                    await scope.Resolve <IExceptionService>().Create(settingsFactory.CreateLog(_settings), _settings.ExceptionLoggingDomainId, ex);
                }
                catch { }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Calling stored procs to delete old purge meta data records
 /// </summary>
 private static async Task PurgMetaData(SettingsFactory settingsFactory, IPurgeSaver saver)
 {
     DateTime     minTimestamp = SubtractSettingsTimespan(DateTime.UtcNow.Date, _settings.PurgeMetaDataTimespan).ToUniversalTime();
     CoreSettings settings     = settingsFactory.CreateCore(_settings);
     await Task.WhenAll(
         saver.DeleteExceptionByMinTimestamp(settings, minTimestamp),
         saver.DeleteMetricByMinTimestamp(settings, minTimestamp),
         saver.DeleteTraceByMinTimestamp(settings, minTimestamp)
         );
 }
Esempio n. 3
0
 /// <summary>
 /// Calling stored procedure to
 /// 1) delete old completed workers
 /// 2) reset hung workers
 /// 3) add domain workers
 /// </summary>
 private static async Task InitializeWorkers()
 {
     using (ILifetimeScope scope = _container.BeginLifetimeScope())
     {
         SettingsFactory   settingsFactory = scope.Resolve <SettingsFactory>();
         IPurgeWorkerSaver saver           = scope.Resolve <IPurgeWorkerSaver>();
         await saver.InitializePurgeWorker(settingsFactory.CreateCore(_settings));
         await WriteTrace(scope.Resolve <ITraceService>(), settingsFactory, "Workers Initialized");
     }
 }
Esempio n. 4
0
        private static async Task PurgeTrace(
            SettingsFactory settingsFactory,
            ITraceService traceService,
            IPurgeSaver purgeSaver,
            Guid domainId)
        {
            DateTime     maxTimestamp = DateTime.UtcNow;
            CoreSettings settings     = settingsFactory.CreateCore(_settings);

            await WriteTrace(traceService, settingsFactory, $"Purging traces");

            await purgeSaver.PurgeTrace(settings, domainId, maxTimestamp);
        }
Esempio n. 5
0
        private static async Task UpdateTraceMetaData(
            SettingsFactory settingsFactory,
            ITraceService traceService,
            IPurgeSaver purgeSaver,
            Guid domainId)
        {
            DateTime     minTimestamp = SubtractSettingsTimespan(DateTime.UtcNow.Date, _settings.RetensionPeriod).ToUniversalTime();
            CoreSettings settings     = settingsFactory.CreateCore(_settings);
            DateTime     expiration   = DateTime.UtcNow;

            expiration = new DateTime(expiration.Year, expiration.Month, 1).AddMonths(1);
            await WriteTrace(traceService, settingsFactory, $"Updating meta data for traces created up to {minTimestamp}");

            await purgeSaver.InitializeTrace(settings, domainId, expiration, minTimestamp);
        }