Beispiel #1
0
        /// <summary>
        /// Cleanups the transient communications.
        /// </summary>
        /// <param name="dataMap">The data map.</param>
        private int CleanupTransientCommunications(JobDataMap dataMap)
        {
            int totalRowsDeleted = 0;
            int?batchAmount      = dataMap.GetString("BatchCleanupAmount").AsIntegerOrNull() ?? 1000;
            var rockContext      = new Rock.Data.RockContext();

            rockContext.Database.CommandTimeout = (int)TimeSpan.FromMinutes(10).TotalSeconds;
            DateTime transientCommunicationExpireDate = RockDateTime.Now.Add(new TimeSpan(7 * -1, 0, 0, 0));
            var      communicationsToDelete           = new CommunicationService(rockContext).Queryable().Where(a => a.CreatedDateTime < transientCommunicationExpireDate && a.Status == CommunicationStatus.Transient);

            totalRowsDeleted = rockContext.BulkDelete(communicationsToDelete, batchAmount);

            return(totalRowsDeleted);
        }
Beispiel #2
0
        /// <summary>
        /// Purges the exception log.
        /// </summary>
        /// <param name="dataMap">The data map.</param>
        private int PurgeExceptionLog(JobDataMap dataMap)
        {
            int totalRowsDeleted    = 0;
            int?batchAmount         = dataMap.GetString("BatchCleanupAmount").AsIntegerOrNull() ?? 1000;
            int?exceptionExpireDays = dataMap.GetString("DaysKeepExceptions").AsIntegerOrNull();

            if (exceptionExpireDays.HasValue)
            {
                var exceptionLogRockContext = new Rock.Data.RockContext();
                exceptionLogRockContext.Database.CommandTimeout = (int)TimeSpan.FromMinutes(10).TotalSeconds;
                DateTime exceptionExpireDate   = RockDateTime.Now.Add(new TimeSpan(exceptionExpireDays.Value * -1, 0, 0, 0));
                var      exceptionLogsToDelete = new ExceptionLogService(exceptionLogRockContext).Queryable().Where(a => a.CreatedDateTime < exceptionExpireDate);

                totalRowsDeleted = exceptionLogRockContext.BulkDelete(exceptionLogsToDelete, batchAmount);
            }

            return(totalRowsDeleted);
        }