Ejemplo 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 { }
            }
        }
Ejemplo n.º 2
0
 public static async Task WriteTrace(ITraceService traceService, SettingsFactory settingsFactory, string value)
 {
     Console.WriteLine(value);
     await traceService.Create(settingsFactory.CreateLog(_settings), _settings.TraceLoggingDomainId, "log-purger", value);
 }