Esempio n. 1
0
        protected override async Task WakeUp(CancellationToken cancellationToken)
        {
            var minCommitTime = (MaxKnownCommitTime - MaxCommitDuration).ToDateTime();

            // Fetching potentially new operations
            var operations = await DbOperationLog
                             .ListNewlyCommitted(minCommitTime, BatchSize, cancellationToken)
                             .ConfigureAwait(false);

            // Processing them
            var tasks = new Task[operations.Count];

            for (var i = 0; i < operations.Count; i++)
            {
                var operation = operations[i];
                var isLocal   = operation.AgentId == AgentInfo.Id.Value;
                // Local completions are invoked by TransientOperationScopeProvider
                // _inside_ the command processing pipeline. Trying to trigger them here
                // means a tiny chance of running them _outside_ of command processing
                // pipeline, which makes it possible to see command completing
                // prior to its invalidation logic completion.
                tasks[i] = isLocal
                    ? Task.CompletedTask // Skips local operation!
                    : OperationCompletionNotifier.NotifyCompleted(operation);
                var commitTime = operation.CommitTime.ToMoment();
                if (MaxKnownCommitTime < commitTime)
                {
                    MaxKnownCommitTime = commitTime;
                }
            }

            // Let's wait when all of these tasks complete, otherwise
            // we might end up creating too many tasks
            await Task.WhenAll(tasks).ConfigureAwait(false);

            LastCount = operations.Count;
        }