protected override async Task WakeUpAsync(CancellationToken cancellationToken) { var minCommitTime = (MaxKnownCommitTime - MaxCommitDuration).ToDateTime(); // Fetching potentially new operations var operations = await DbOperationLog .ListNewlyCommittedAsync(minCommitTime, cancellationToken) .ConfigureAwait(false); // var secondsAgo = (Clock.Now.ToDateTime() - minCommitTime).TotalSeconds; // Log.LogInformation("({Ago:F2}s ago ... now): {OpCount} operations", // secondsAgo, operations.Count); // Processing them foreach (var operation in operations) { OperationCompletionNotifier.NotifyCompleted(operation); var commitTime = operation.CommitTime.ToMoment(); if (MaxKnownCommitTime < commitTime) { // This update should happen even for locally executed operations, // i.e. when NotifyCompleted(...) returns false! MaxKnownCommitTime = commitTime; } } }
protected override async Task WakeUp(CancellationToken cancellationToken) { var minCommitTime = (Clock.Now - MaxCommitAge).ToDateTime(); LastTrimCount = await DbOperationLog .Trim(minCommitTime, BatchSize, cancellationToken) .ConfigureAwait(false); if (LastTrimCount > 0 && IsLoggingEnabled) { Log.Log(LogLevel, "Trimmed {Count} operations", LastTrimCount); } }
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; }