protected internal override async Task <InvocationResult> Invoke()
        {
            DateTimeOffset before;

            if (MinAge != null)
            {
                before = DateTimeOffset.UtcNow - MinAge.Value;
            }
            else
            {
                before = Before ?? DateTimeOffset.UtcNow;
            }

            // Get purgable invocations
            Log.FindingPurgableInvocations(before);
            var purgable = (await Context.Queue.GetPurgable(before)).ToList();

            Log.FoundPurgableInvocations(purgable.Count, before);

            // Purge 'em
            Log.PurgingInvocations(purgable.Count);
            await Context.Queue.Purge(purgable.Select(i => i.Id));

            Log.PurgedInvocations(purgable.Count);

            return(InvocationResult.Completed());
        }
Exemplo n.º 2
0
            public async Task AcknowledgesMessageOnCompletionOfInvocation()
            {
                // Arrange
                var cts        = new CancellationTokenSource();
                var runner     = new TestableJobRunner(TimeSpan.FromSeconds(5));
                var invocation = TestHelpers.CreateInvocation(Guid.NewGuid(), "test", "test", new Dictionary <string, string>());

                runner.MockDispatcher
                .Setup(d => d.Dispatch(It.IsAny <InvocationContext>()))
                .Completes(InvocationResult.Completed())
                .Verifiable();

                // Act
                await runner.Dispatch(invocation, cts.Token);

                // Assert
                runner.MockQueue.Verify(q => q.Complete(invocation, ExecutionResult.Completed, null, null));
            }
Exemplo n.º 3
0
            public async Task DispatchesTheJobUsingTheDispatcher()
            {
                // Arrange
                var cts        = new CancellationTokenSource();
                var runner     = new TestableJobRunner(TimeSpan.FromSeconds(5));
                var invocation = TestHelpers.CreateInvocation(Guid.NewGuid(), "test", "test", new Dictionary <string, string>());

                runner.MockDispatcher
                .Setup(d => d.Dispatch(It.IsAny <InvocationContext>()))
                .Completes(InvocationResult.Completed())
                .Verifiable();

                // Act
                await runner.Dispatch(invocation, cts.Token);

                // Assert
                runner.MockDispatcher.VerifyAll();
            }
Exemplo n.º 4
0
            public async Task UpdatesTheStatusOfTheRequestToExecuting()
            {
                // Arrange
                var cts        = new CancellationTokenSource();
                var runner     = new TestableJobRunner(TimeSpan.FromSeconds(5));
                var invocation = TestHelpers.CreateInvocation(Guid.NewGuid(), "test", "test", new Dictionary <string, string>());

                var dispatchTCS = runner
                                  .MockDispatcher
                                  .Setup(d => d.Dispatch(It.IsAny <InvocationContext>()))
                                  .WaitsForSignal();

                // Act
                var task = runner.Dispatch(invocation, cts.Token);

                // Assert
                runner.MockQueue.Verify(q => q.UpdateStatus(invocation, InvocationStatus.Executing, ExecutionResult.Incomplete));

                dispatchTCS.SetResult(InvocationResult.Completed());

                await task;
            }