Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Commit 9061408

Browse files
committed
Use RunOnce for jobs that maintain their own loop (#487)
Progress on NuGet/Engineering#1543
1 parent e878894 commit 9061408

4 files changed

Lines changed: 31 additions & 11 deletions

File tree

src/NuGet.Jobs.Common/JobRunner.cs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,16 @@ private static async Task Run(JobBase job, string[] commandLineArgs, bool? runCo
9191
// Configure our logging again with Application Insights initialized.
9292
loggerFactory = ConfigureLogging(job);
9393

94-
runContinuously = runContinuously ?? !JobConfigurationManager.TryGetBoolArgument(jobArgsDictionary, JobArgumentNames.Once);
94+
var hasOnceArgument = JobConfigurationManager.TryGetBoolArgument(jobArgsDictionary, JobArgumentNames.Once);
95+
96+
if (runContinuously.HasValue && hasOnceArgument)
97+
{
98+
_logger.LogWarning(
99+
$"This job is designed to {(runContinuously.Value ? "run continuously" : "run once")} so " +
100+
$"the -{JobArgumentNames.Once} argument is {(runContinuously.Value ? "ignored" : "redundant")}.");
101+
}
102+
103+
runContinuously = runContinuously ?? !hasOnceArgument;
95104
var reinitializeAfterSeconds = JobConfigurationManager.TryGetIntArgument(jobArgsDictionary, JobArgumentNames.ReinitializeAfterSeconds);
96105
var sleepDuration = JobConfigurationManager.TryGetIntArgument(jobArgsDictionary, JobArgumentNames.Sleep); // sleep is in milliseconds
97106

@@ -104,18 +113,34 @@ private static async Task Run(JobBase job, string[] commandLineArgs, bool? runCo
104113
}
105114
}
106115

107-
if (sleepDuration == null)
116+
if (!sleepDuration.HasValue)
108117
{
109-
_logger.LogInformation("SleepDuration is not provided or is not a valid integer. Unit is milliSeconds. Assuming default of 5000 ms...");
118+
if (runContinuously.Value)
119+
{
120+
_logger.LogInformation("SleepDuration is not provided or is not a valid integer. Unit is milliSeconds. Assuming default of 5000 ms...");
121+
}
122+
110123
sleepDuration = 5000;
111124
}
125+
else if (!runContinuously.Value)
126+
{
127+
_logger.LogWarning(
128+
$"The job is designed to run once so the -{JobArgumentNames.Sleep} and " +
129+
$"-{JobArgumentNames.Interval} arguments are ignored.");
130+
}
112131

113132
if (!reinitializeAfterSeconds.HasValue)
114133
{
115134
_logger.LogInformation(
116135
$"{JobArgumentNames.ReinitializeAfterSeconds} command line argument is not provided or is not a valid integer. " +
117136
"The job will reinitialize on every iteration");
118137
}
138+
else if (!runContinuously.Value)
139+
{
140+
_logger.LogWarning(
141+
$"The job is designed to run once so the -{JobArgumentNames.ReinitializeAfterSeconds} " +
142+
$"argument is ignored.");
143+
}
119144

120145
// Ensure that SSLv3 is disabled and that Tls v1.2 is enabled.
121146
ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Ssl3;

src/NuGet.Services.Validation.Orchestrator/Program.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using System.Linq;
54
using NuGet.Jobs;
65

76
namespace NuGet.Services.Validation.Orchestrator
@@ -10,12 +9,8 @@ class Program
109
{
1110
static int Main(string[] args)
1211
{
13-
if (!args.Contains(JobArgumentNames.Once))
14-
{
15-
args = args.Concat(new[] { "-" + JobArgumentNames.Once }).ToArray();
16-
}
1712
var job = new Job();
18-
JobRunner.Run(job, args).GetAwaiter().GetResult();
13+
JobRunner.RunOnce(job, args).GetAwaiter().GetResult();
1914

2015
// if configuration validation failed, return non-zero status so we can detect failures in automation
2116
return job.ConfigurationValidated ? 0 : 1;

src/Validation.PackageSigning.ProcessSignature/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class Program
88
public static void Main(string[] args)
99
{
1010
var job = new Job();
11-
JobRunner.Run(job, args).GetAwaiter().GetResult();
11+
JobRunner.RunOnce(job, args).GetAwaiter().GetResult();
1212
}
1313
}
1414
}

src/Validation.PackageSigning.ValidateCertificate/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Program
1010
static void Main(string[] args)
1111
{
1212
var job = new Job();
13-
JobRunner.Run(job, args).GetAwaiter().GetResult();
13+
JobRunner.RunOnce(job, args).GetAwaiter().GetResult();
1414
}
1515
}
1616
}

0 commit comments

Comments
 (0)