Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved logic to drain queues after each task under knob "AGENT_DRAIN_QUEUES_AFTER_TASK" #4176

Merged
Merged
7 changes: 7 additions & 0 deletions src/Agent.Sdk/Knob/AgentKnobs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,5 +410,12 @@ public class AgentKnobs
new RuntimeKnobSource("AGENT_USE_NODE"),
new EnvironmentKnobSource("AGENT_USE_NODE"),
new BuiltInDefaultKnobSource(string.Empty));

public static readonly Knob DrainQueuesAfterTask = new Knob(
nameof(DrainQueuesAfterTask),
"Forces the agent to drain queues after each task",
new RuntimeKnobSource("AGENT_DRAIN_QUEUES_AFTER_TASK"),
new EnvironmentKnobSource("AGENT_DRAIN_QUEUES_AFTER_TASK"),
new BuiltInDefaultKnobSource("false"));
}
}
22 changes: 13 additions & 9 deletions src/Agent.Worker/StepsRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.TeamFoundation.DistributedTask.Expressions;
using Pipelines = Microsoft.TeamFoundation.DistributedTask.Pipelines;
using Microsoft.VisualStudio.Services.CircuitBreaker;
using Agent.Sdk.Knob;

namespace Microsoft.VisualStudio.Services.Agent.Worker
{
Expand Down Expand Up @@ -309,16 +310,19 @@ private async Task RunStepAsync(IStep step, CancellationToken jobCancellationTok
step.ExecutionContext.Section(StringUtil.Loc("StepFinishing", step.DisplayName));
step.ExecutionContext.Complete();

try
{
// We need to drain the queues after a task just in case if
// there are a lot of items since it can cause some UI hangs.
await JobServerQueue.DrainQueues();
}
catch (Exception ex)
if (AgentKnobs.DrainQueuesAfterTask.GetValue(step.ExecutionContext).AsBoolean() == true)
{
Trace.Error($"Error has occurred while draining queues, it can cause some UI glitches but it doesn't affect a pipeline execution itself: {ex}");
step.ExecutionContext.Error(ex);
try
{
// We need to drain the queues after a task just in case if
// there are a lot of items since it can cause some UI hangs.
await JobServerQueue.DrainQueues();
}
catch (Exception ex)
{
Trace.Error($"Error has occurred while draining queues, it can cause some UI glitches but it doesn't affect a pipeline execution itself: {ex}");
step.ExecutionContext.Error(ex);
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/Test/L0/Worker/StepsRunnerL0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Xunit;
using Microsoft.TeamFoundation.DistributedTask.Expressions;
using Pipelines = Microsoft.TeamFoundation.DistributedTask.Pipelines;
using Agent.Sdk;

namespace Microsoft.VisualStudio.Services.Agent.Tests.Worker
{
Expand Down Expand Up @@ -426,6 +427,7 @@ public async Task SetStepTarget()
stepContext.Object.Result = r;
}
});
stepContext.Setup(x => x.GetScopedEnvironment()).Returns(new SystemEnvironment());
step.Setup(x => x.ExecutionContext).Returns(stepContext.Object);

// Act.
Expand Down Expand Up @@ -460,6 +462,7 @@ private Mock<IStep> CreateStep(TaskResult result, IExpressionNode condition, Boo
}
});
stepContext.Object.Result = result;
stepContext.Setup(x => x.GetScopedEnvironment()).Returns(new SystemEnvironment());
step.Setup(x => x.ExecutionContext).Returns(stepContext.Object);

return step;
Expand Down