Skip to content

Commit

Permalink
c
Browse files Browse the repository at this point in the history
  • Loading branch information
TingluoHuang committed Jan 2, 2020
1 parent bf3d990 commit 239f300
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/Runner.Listener/JobDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,8 @@ await processChannel.SendAsync(
Trace.Info("worker process has been killed.");
}

// When worker doesn't exit within cancel timeout, the runner will kill the worker process and worker won't finish upload job logs.
// The runner will try to upload these logs at this time.
await TryUploadUnfinishedLogs(message);
}

Expand Down Expand Up @@ -755,12 +757,22 @@ private async Task TryUploadUnfinishedLogs(Pipelines.AgentJobRequestMessage mess
var pageNumber = 0;
if (logPageSeperator < 0)
{
logRecordId = Guid.Parse(logName);
Trace.Warning($"log file '{log}' doesn't follow naming convension 'GUID_INT'.");
continue;
}
else
{
logRecordId = Guid.Parse(logName.Substring(0, logPageSeperator));
pageNumber = int.Parse(logName.Substring(logPageSeperator + 1));
if (!Guid.TryParse(logName.Substring(0, logPageSeperator), out logRecordId))
{
Trace.Warning($"log file '{log}' doesn't follow naming convension 'GUID_INT'.");
continue;
}

if (!int.TryParse(logName.Substring(logPageSeperator + 1), out pageNumber))
{
Trace.Warning($"log file '{log}' doesn't follow naming convension 'GUID_INT'.");
continue;
}
}

var record = timeline.Records.FirstOrDefault(x => x.Id == logRecordId);
Expand All @@ -784,10 +796,11 @@ private async Task TryUploadUnfinishedLogs(Pipelines.AgentJobRequestMessage mess
// Create the log
record.Log = await jobServer.CreateLogAsync(message.Plan.ScopeIdentifier, message.Plan.PlanType, message.Plan.PlanId, new TaskLog(String.Format(@"logs\{0:D}", record.Id)), default(CancellationToken));

// Need to post timeline record updates to reflect the log creation
updatedRecords.Add(record.Clone());
}

for (var i = 0; i < pages.Value.Count; i++)
for (var i = 1; i <= pages.Value.Count; i++)
{
var logFile = pages.Value[i];
// Upload the contents
Expand All @@ -796,7 +809,7 @@ private async Task TryUploadUnfinishedLogs(Pipelines.AgentJobRequestMessage mess
var logUploaded = await jobServer.AppendLogContentAsync(message.Plan.ScopeIdentifier, message.Plan.PlanType, message.Plan.PlanId, record.Log.Id, fs, default(CancellationToken));
}

Trace.Info($"Uploaded '{logFile}' for current job.");
Trace.Info($"Uploaded unfinished log '{logFile}' for current job.");
IOUtil.DeleteFile(logFile);
}
}
Expand Down

0 comments on commit 239f300

Please sign in to comment.