private void ScheduleForkIfNeeded(List <Task> currentTasks, Request request, IRequestTimeBudget budget, int currentReplicaIndex, int totalReplicas, CancellationToken cancellationToken)
        {
            if (currentReplicaIndex == totalReplicas - 1)
            {
                return;
            }

            if (currentTasks.Count >= maximumParallelism)
            {
                return;
            }

            var forkingDelay = delaysProvider.GetForkingDelay(request, budget, currentReplicaIndex, totalReplicas);

            if (forkingDelay == null)
            {
                return;
            }

            if (forkingDelay.Value < TimeSpan.Zero)
            {
                return;
            }

            if (forkingDelay.Value >= budget.Remaining)
            {
                return;
            }

            currentTasks.Add(delaysPlanner.Plan(forkingDelay.Value, cancellationToken));
        }
Example #2
0
 private void SetupForkingDelays(TimeSpan?first, params TimeSpan?[] next)
 {
     delaysProvider
     .GetForkingDelay(Arg.Any <Request>(), Arg.Any <IRequestTimeBudget>(), Arg.Any <int>(), Arg.Any <int>())
     .Returns(first, next);
 }