Ejemplo n.º 1
0
        public void Expire_ExpiresSetAndHash()
        {
            var expiration = new ConsoleExpirationTransaction(_transaction.Object);

            expiration.Expire(_consoleId, TimeSpan.FromHours(1));

            _transaction.Verify(x => x.ExpireSet(_consoleId.GetSetKey(), It.IsAny <TimeSpan>()));
            _transaction.Verify(x => x.ExpireHash(_consoleId.GetHashKey(), It.IsAny <TimeSpan>()));

            // backward compatibility:
            _transaction.Verify(x => x.ExpireSet(_consoleId.GetOldConsoleKey(), It.IsAny <TimeSpan>()));
            _transaction.Verify(x => x.ExpireHash(_consoleId.GetOldConsoleKey(), It.IsAny <TimeSpan>()));
        }
Ejemplo n.º 2
0
        public void OnStateApplied(ApplyStateContext context, IWriteOnlyTransaction transaction)
        {
            if (!_options.FollowJobRetentionPolicy)
            {
                // Console sessions use their own expiration timeout.
                // Do not expire here, will be expired by ConsoleServerFilter.
                return;
            }

            var jobDetails = context.Storage.GetMonitoringApi().JobDetails(context.BackgroundJob.Id);

            if (jobDetails == null || jobDetails.History == null)
            {
                // WTF?!
                return;
            }

            var expiration = new ConsoleExpirationTransaction((JobStorageTransaction)transaction);

            foreach (var state in jobDetails.History.Where(x => x.StateName == ProcessingState.StateName))
            {
                var consoleId = new ConsoleId(context.BackgroundJob.Id, JobHelper.DeserializeDateTime(state.Data["StartedAt"]));

                if (context.NewState.IsFinal)
                {
                    // Job in final state is a subject for expiration.
                    // To keep storage clean, its console sessions should also be expired.
                    expiration.Expire(consoleId, context.JobExpirationTimeout);
                }
                else
                {
                    // Job will be persisted, so should its console sessions.
                    expiration.Persist(consoleId);
                }
            }
        }
Ejemplo n.º 3
0
        public void Expire_ThrowsException_IfConsoleIdIsNull()
        {
            var expiration = new ConsoleExpirationTransaction(_transaction.Object);

            Assert.Throws <ArgumentNullException>("consoleId", () => expiration.Expire(null, TimeSpan.FromHours(1)));
        }