From 29a04f0e12a4ad2091e2fcd8814de5c704671bde Mon Sep 17 00:00:00 2001 From: Matt Galbraith Date: Tue, 19 Oct 2021 13:10:15 -0700 Subject: [PATCH] In preparation of removing deadlettered queues, teach the SDK to optionally ignore when a queue does not exist. --- .../JobSender/JobDefinition.cs | 11 ++++++++ src/Microsoft.DotNet.Helix/Sdk/HelixTask.cs | 18 +++++++++++++ src/Microsoft.DotNet.Helix/Sdk/Readme.md | 27 ++++++++----------- ...crosoft.DotNet.Helix.Sdk.MonoQueue.targets | 10 ++++++- 4 files changed, 49 insertions(+), 17 deletions(-) diff --git a/src/Microsoft.DotNet.Helix/JobSender/JobDefinition.cs b/src/Microsoft.DotNet.Helix/JobSender/JobDefinition.cs index b5b782beec6..078cff49c71 100644 --- a/src/Microsoft.DotNet.Helix/JobSender/JobDefinition.cs +++ b/src/Microsoft.DotNet.Helix/JobSender/JobDefinition.cs @@ -154,6 +154,17 @@ public async Task SendAsync(Action log, CancellationToken canc var (queueId, dockerTag, queueAlias) = ParseQueueId(TargetQueueId); + // Save time / resources by checking that the queue isn't missing before doing any potentially expensive storage operations + try + { + QueueInfo queueInfo = await HelixApi.Information.QueueInfoAsync(queueId, false, cancellationToken); + } + // 404 = this queue does not exist, or did and was removed. + catch (RestApiException ex) when (ex.Response?.Status == 404) + { + throw new ArgumentException($"Helix API does not contain an entry for {queueId}"); + } + IBlobContainer storageContainer = await storage.GetContainerAsync(TargetContainerName, queueId, cancellationToken); var jobList = new List(); diff --git a/src/Microsoft.DotNet.Helix/Sdk/HelixTask.cs b/src/Microsoft.DotNet.Helix/Sdk/HelixTask.cs index c411bdca5b3..caa5ae3aef1 100644 --- a/src/Microsoft.DotNet.Helix/Sdk/HelixTask.cs +++ b/src/Microsoft.DotNet.Helix/Sdk/HelixTask.cs @@ -21,6 +21,13 @@ public abstract class HelixTask : BaseTask, ICancelableTask /// public string AccessToken { get; set; } + /// + /// If , fail when posting jobs to non-existent queues; If allow it and print a warning. + /// Note if an MSBuild sequence starts and waits on jobs, and none are started, this will still fail. + /// Defined on HelixTask so the catch block around Execute() can know about it. + /// + public bool FailOnMissingTargetQueue { get; set; } = true; + protected IHelixApi HelixApi { get; private set; } protected IHelixApi AnonymousApi { get; private set; } @@ -63,6 +70,17 @@ public sealed override bool Execute() // Canceled return false; } + catch (ArgumentException argEx) when (argEx.Message.StartsWith("Helix API does not contain an entry ")) + { + if (FailOnMissingTargetQueue) + { + Log.LogError(FailureCategory.Build, argEx.Message); + } + else + { + Log.LogWarning($"{argEx.Message} (FailOnMissingTargetQueue is false, so this is just a warning.)"); + } + } catch (Exception ex) { Log.LogErrorFromException(FailureCategory.Helix, ex, true, true, null); diff --git a/src/Microsoft.DotNet.Helix/Sdk/Readme.md b/src/Microsoft.DotNet.Helix/Sdk/Readme.md index eb8ca7fe33f..661cafdff4b 100644 --- a/src/Microsoft.DotNet.Helix/Sdk/Readme.md +++ b/src/Microsoft.DotNet.Helix/Sdk/Readme.md @@ -1,9 +1,9 @@ # Microsoft.DotNet.Helix.Sdk -This Package provides Helix Job sending functionality from an MSBuild project file. +This Package provides Helix Job-sending functionality from an MSBuild project file. ## Examples -Each of the following examples require dotnet-cli >= 2.1.300 and need the following files in a directory at or above the example project's directory. +Each of the following examples require dotnet-cli >= 3.1.x, and need the following files in a directory at or above the example project's directory. #### NuGet.config ```xml @@ -149,13 +149,21 @@ Given a local folder `$(TestFolder)` containing `runtests.cmd`, this will run `r Windows.10.Amd64.Open + + false + - Ubuntu.1804.Amd64.Open;Ubuntu.1604.Amd64.Open;(Alpine.39.Amd64)Ubuntu.1604.Amd64.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:alpine-3.9-helix-bfcd90a-20200123191053 + Ubuntu.1804.Amd64.Open;Ubuntu.1604.Amd64.Open;(Alpine.39.Amd64)Ubuntu.1804.Amd64.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:alpine-3.9-helix-bfcd90a-20200123191053 true @@ -171,18 +179,6 @@ Given a local folder `$(TestFolder)` containing `runtests.cmd`, this will run `r true - - - false - + true + + $(RepositoryEngineeringDir)/test-configuration.json @@ -38,6 +45,7 @@