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

Catch agent updating exception #4082

Merged
merged 2 commits into from
Dec 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/Agent.Listener/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ private async Task<int> RunAsync(AgentSettings settings, bool runOnce = false)
Task<bool> selfUpdateTask = null;
bool runOnceJobReceived = false;
jobDispatcher = HostContext.CreateService<IJobDispatcher>();
TaskAgentMessage previuosMessage = null;

while (!HostContext.AgentShutdownToken.IsCancellationRequested)
{
Expand All @@ -338,7 +339,18 @@ private async Task<int> RunAsync(AgentSettings settings, bool runOnce = false)
if (completeTask == selfUpdateTask)
{
autoUpdateInProgress = false;
if (await selfUpdateTask)

bool agentUpdated = false;
try
{
agentUpdated = await selfUpdateTask;
}
catch (Exception ex)
{
Trace.Info($"Ignore agent update exception. {ex}");
}

if (agentUpdated)
{
Trace.Info("Auto update task finished at backend, an agent update is ready to apply exit the current agent instance.");
Trace.Info("Stop message queue looping.");
Expand All @@ -365,6 +377,9 @@ private async Task<int> RunAsync(AgentSettings settings, bool runOnce = false)
{
Trace.Info("Auto update task finished at backend, there is no available agent update needs to apply, continue message queue looping.");
}

message = previuosMessage;// if agent wasn't updated it's needed to process the previous message
previuosMessage = null;
}
}

Expand All @@ -390,7 +405,7 @@ private async Task<int> RunAsync(AgentSettings settings, bool runOnce = false)
}
}

message = await getNextMessage; //get next message
message ??= await getNextMessage; //get next message
HostContext.WritePerfCounter($"MessageReceived_{message.MessageType}");
if (string.Equals(message.MessageType, AgentRefreshMessage.MessageType, StringComparison.OrdinalIgnoreCase))
{
Expand All @@ -417,6 +432,11 @@ private async Task<int> RunAsync(AgentSettings settings, bool runOnce = false)
else if (string.Equals(message.MessageType, JobRequestMessageTypes.AgentJobRequest, StringComparison.OrdinalIgnoreCase) ||
string.Equals(message.MessageType, JobRequestMessageTypes.PipelineAgentJobRequest, StringComparison.OrdinalIgnoreCase))
{
if (autoUpdateInProgress)
{
previuosMessage = message;
}

if (autoUpdateInProgress || runOnceJobReceived)
{
skipMessageDeletion = true;
Expand Down