Esempio n. 1
0
 public MaintenanceWorkItem(MaintenanceConfiguration configuration)
 {
     if (configuration == null)
     {
         throw new ArgumentNullException("configuration");
     }
     this.Configuration = configuration;
 }
        public override bool IsDisabled(ITaskExecutionContext context)
        {
            MaintenanceConfiguration configuration = _configuration.Get <MaintenanceConfiguration>();

            context.TypedBag(ConfigurationName, configuration);

            return(configuration.Disabled);
        }
Esempio n. 3
0
        public MaintenanceWorkItem(MaintenanceConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            Configuration = configuration;
        }
        private Tuple <int, string> DeleteEntries(MaintenanceConfiguration configuration, IDbSession session, IntegrationDbTable table, DateTimeOffset lowerBound)
        {
            return(session.Wrap(s =>
            {
                string csv = null;
                string tableName = _dbConfiguration.TableName(table);
                int batchSize = configuration.DeleteLogEntriesBatchSize;

                if (configuration.ArchiveDeletedLogEntries)
                {
                    string query = $"SELECT * FROM [{tableName}] WHERE [TimeStamp] <= @lowerbound";
                    csv = s.QueryToCsv(query, new { lowerBound });
                }

                int count = s.Execute(GetDeleteSql(tableName), new { lowerBound, batchSize }, configuration.CleanUpCommandTimeout.GetValueOrDefault(10800));

                return Tuple.Create(count, csv);
            }));
        }
        public override void Execute(ITaskExecutionContext <MaintenanceWorkItem> context)
        {
            MaintenanceConfiguration configuration = _configuration.Get <MaintenanceConfiguration>();

            DateTimeOffset tasksLowerBound  = Time.UtcNow.Subtract(context.WorkItem.Configuration.CleanUpTaskLogEntriesOlderThan),
                           errorsLowerBound = Time.UtcNow.Subtract(context.WorkItem.Configuration.CleanUpErrorLogEntriesOlderThan);

            using (IDbSession session = _db.Value.OpenSession())
            {
                Tuple <int, string> taskLog  = DeleteEntries(configuration, session, IntegrationDbTable.TaskLog, tasksLowerBound);
                Tuple <int, string> errorLog = DeleteEntries(configuration, session, IntegrationDbTable.ErrorLog, errorsLowerBound);

                if (taskLog.Item1 > 0 || errorLog.Item1 > 0)
                {
                    ArchiveCreated archive = null;

                    if (configuration.ArchiveDeletedLogEntries)
                    {
                        archive = _archiver.Archive("IntegrationDb-Maintenance", a =>
                        {
                            a.Options
                            .GroupedBy("Backup")
                            .ExpiresAfterMonths(12)
                            .Compression(CompressionLevel.Optimal);

                            a.IncludeContent($"TaskLog_{tasksLowerBound:yyyyMMdd}.csv", taskLog.Item2);
                            a.IncludeContent($"ErrorLog_{errorsLowerBound:yyyyMMdd}.csv", errorLog.Item2);
                        });
                    }

                    context.Log.Message(@"Deleted {0} task entries older than '{1}'. 
Deleted {2} error entries older than '{3}'
Archive: {4}",
                                        taskLog.Item1,
                                        tasksLowerBound,
                                        errorLog.Item1,
                                        errorsLowerBound,
                                        archive ?? "<Not archived>");
                }
            }
        }
        public override MaintenanceWorkItem Start(ITaskExecutionContext context)
        {
            MaintenanceConfiguration configuration = context.TypedBag <MaintenanceConfiguration>(ConfigurationName);

            return(new MaintenanceWorkItem(configuration));
        }