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

            expiration.Persist(_consoleId);

            _transaction.Verify(x => x.PersistSet(_consoleId.GetSetKey()));
            _transaction.Verify(x => x.PersistHash(_consoleId.GetHashKey()));

            // backward compatibility:
            _transaction.Verify(x => x.PersistSet(_consoleId.GetOldConsoleKey()));
            _transaction.Verify(x => x.PersistHash(_consoleId.GetOldConsoleKey()));
        }
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 Persist_ThrowsException_IfConsoleIdIsNull()
        {
            var expiration = new ConsoleExpirationTransaction(_transaction.Object);

            Assert.Throws <ArgumentNullException>("consoleId", () => expiration.Persist(null));
        }