Exemple #1
0
        /// <inheritdoc />
        public async Task <long> WorkAsync(CancellationToken token)
        {
            // check if we are active at the current time.
            if (!_active.IsActive())
            {
                // we are not active ... so we have nothing to do.
                _logger.Verbose("Maintenance Process ignored, out of active hours.");
                return(0);
            }

            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var success = false;

            try
            {
                _logger.Information("Started Maintenance Process.");
                await _persister.MaintenanceAsync(token).ConfigureAwait(false);

                await _parser.MaintenanceAsync(token).ConfigureAwait(false);

                // it worked
                success = true;
            }
            catch (OperationCanceledException)
            {
                // nothing to log
                throw;
            }
            catch (Exception e)
            {
                _logger.Exception("Error while processing Maintenance.", e);
                throw;
            }
            finally
            {
                _logger.Information(success
          ? $"Complete Maintenance Process (Time Elapsed: {stopwatch.Elapsed:g})."
          : $"Complete Maintenance Process with errors (Time Elapsed: {stopwatch.Elapsed:g}).");
            }
            return(0);
        }