Example #1
0
        /// <summary>
        /// Run expiration manager to remove outdated records
        /// </summary>
        /// <param name="cancellationToken">Cancellation token</param>
        public void Execute(CancellationToken cancellationToken)
        {
            HangfireDbContext connection = _storage.CreateAndOpenConnection();
            DateTime          now        = DateTime.UtcNow;

            RemoveExpiredRecord(connection.Job, _ => _.ExpireAt < now && _.ExpireAt != null);
            RemoveExpiredRecord(connection.StateDataAggregatedCounter, _ => _.ExpireAt < now && _.ExpireAt != null);
            RemoveExpiredRecord(connection.StateDataCounter, _ => _.ExpireAt < now && _.ExpireAt != null);
            RemoveExpiredRecord(connection.StateDataHash, _ => _.ExpireAt < now && _.ExpireAt != null);
            RemoveExpiredRecord(connection.StateDataSet, _ => _.ExpireAt < now && _.ExpireAt != null);
            RemoveExpiredRecord(connection.StateDataList, _ => _.ExpireAt < now && _.ExpireAt != null);
            cancellationToken.WaitHandle.WaitOne(_checkInterval);
        }
        /// <summary>
        /// Run expiration manager to remove outdated records
        /// </summary>
        /// <param name="cancellationToken">Cancellation token</param>
        public void Execute(CancellationToken cancellationToken)
        {
            HangfireDbContext connection = _storage.CreateAndOpenConnection();
            DateTime          now        = DateTime.UtcNow;

            // TounviersalTime() is not supported in BsonExpression
            // _ => _.ExpireAt != null && _.ExpireAt.Value.ToUniversalTime() < now
            // Assume the values being pushed are always universal time instead

            RemoveExpiredRecord(connection, connection.Job, _ => _.ExpireAt != null && _.ExpireAt.Value < now);
            RemoveExpiredRecord(connection, connection.StateDataAggregatedCounter, _ => _.ExpireAt != null && _.ExpireAt.Value < now);
            RemoveExpiredRecord(connection, connection.StateDataCounter, _ => _.ExpireAt != null && _.ExpireAt.Value < now);
            RemoveExpiredRecord(connection, connection.StateDataHash, _ => _.ExpireAt != null && _.ExpireAt.Value < now);
            RemoveExpiredRecord(connection, connection.StateDataSet, _ => _.ExpireAt != null && _.ExpireAt.Value < now);
            RemoveExpiredRecord(connection, connection.StateDataList, _ => _.ExpireAt != null && _.ExpireAt.Value < now);

            cancellationToken.WaitHandle.WaitOne(_checkInterval);
        }