Skip to content

Commit

Permalink
[WIP] Trying out the AzDO pipeline warnings by setting the warning wi…
Browse files Browse the repository at this point in the history
…ndow to the next 2,100, not 21, days.
  • Loading branch information
MattGal committed Dec 17, 2021
1 parent 25494ac commit a528d43
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/Microsoft.DotNet.Helix/JobSender/JobDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Collections.ObjectModel;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -158,6 +159,7 @@ public async Task<ISentJob> SendAsync(Action<string> log, CancellationToken canc
try
{
QueueInfo queueInfo = await HelixApi.Information.QueueInfoAsync(queueId, false, cancellationToken);
WarnForImpendingRemoval(log, queueInfo);
}
// 404 = this queue does not exist, or did and was removed.
catch (RestApiException ex) when (ex.Response?.Status == 404)
Expand Down Expand Up @@ -234,6 +236,36 @@ public async Task<ISentJob> SendAsync(Action<string> log, CancellationToken canc
return new SentJob(JobApi, newJob, newJob.ResultsUri, newJob.ResultsUriRSAS);
}

private void WarnForImpendingRemoval(Action<string> log, QueueInfo queueInfo)
{
bool azDoVariableDefined = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SYSTEM_TEAMPROJECT"));
DateTime whenItExpires = DateTime.MaxValue;

if (DateTime.TryParseExact(queueInfo.EstimatedRemovalDate, "yyyy-MM-dd", null, DateTimeStyles.AssumeUniversal, out DateTime dtIso))
{
whenItExpires = dtIso;
}
// This branch can be removed once the strings start coming in in ISO-8601 format
// Currently the API provides values in this format though and they are unlikely to get confused with each other.
else if (DateTime.TryParseExact(queueInfo.EstimatedRemovalDate, "M/d/yyyy", null, DateTimeStyles.AssumeUniversal, out DateTime dtUsa))
{
whenItExpires = dtUsa;
}

if (whenItExpires != DateTime.MaxValue) // We recognized a date from the string
{
TimeSpan untilRemoved = whenItExpires.ToUniversalTime().Subtract(DateTime.UtcNow);
if (untilRemoved.TotalDays <= 2100) // This will be 21, it's set to 21 to demonstrate the warnings in a pipeline for a do-not-merge draft PR
{
Console.WriteLine($"{(azDoVariableDefined ? "##vso[task.logissue type=warning]" : "")}Helix queue {queueInfo.QueueId} {(untilRemoved.TotalDays < 0 ? "was" : "is")} slated for removal on {queueInfo.EstimatedRemovalDate}. Please discontinue usage. Contact dnceng for questions / concerns ");
}
}
else
{
Console.WriteLine($"{(azDoVariableDefined ? "##vso[task.logissue type=warning]" : "")}Unable to parse estimated removal date '{queueInfo.EstimatedRemovalDate}' for queue '{queueInfo.QueueId}' (please contact dnceng with this information)");
}
}

private (string queueId, string dockerTag, string queueAlias) ParseQueueId(string value)
{
var @index = value.IndexOf('@');
Expand Down

0 comments on commit a528d43

Please sign in to comment.