From 147c2d30b2b29d6f5140a8366891876e0e92ee0a Mon Sep 17 00:00:00 2001 From: Joseph Weinkam Date: Fri, 24 Mar 2023 10:53:01 -0700 Subject: [PATCH] background task scheduling clean up --- src/EMBC.DFA/Services/BackgroundTask.cs | 11 ++++------- src/EMBC.DFA/Services/GovBackgroundTask.cs | 5 +---- src/EMBC.DFA/Services/IndBackgroundTask.cs | 5 +---- src/EMBC.DFA/Services/SmbBackgroundTask.cs | 5 +---- 4 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/EMBC.DFA/Services/BackgroundTask.cs b/src/EMBC.DFA/Services/BackgroundTask.cs index 99791cf..4503a65 100644 --- a/src/EMBC.DFA/Services/BackgroundTask.cs +++ b/src/EMBC.DFA/Services/BackgroundTask.cs @@ -16,10 +16,8 @@ namespace EMBC.DFA.Services public interface IBackgroundTask { public string Schedule { get; } - public string TestSchedule { get; } //increased frequency schedule for TEST environment public int DegreeOfParallelism { get; } - public TimeSpan InitialDelay { get; } - public TimeSpan FastDelay { get; } + public int InitialDelay { get; } TimeSpan InactivityTimeout { get; } public Task ExecuteAsync(CancellationToken cancellationToken); @@ -44,10 +42,9 @@ public BackgroundTask(IServiceProvider serviceProvider, IDistributedSemaphorePro var task = scope.ServiceProvider.GetRequiredService(); var appName = Environment.GetEnvironmentVariable("APP_NAME") ?? Assembly.GetEntryAssembly()?.GetName().Name ?? string.Empty; - var scheduleToUse = serviceProvider.GetRequiredService().GetValue("USE_TEST_SCHEDULE", false) ? task.TestSchedule : task.Schedule; - - schedule = CronExpression.Parse(configuration.GetValue("schedule", scheduleToUse), CronFormat.IncludeSeconds); - startupDelay = serviceProvider.GetRequiredService().GetValue("USE_FAST_DELAY", false) ? configuration.GetValue("initialDelay", task.FastDelay) : configuration.GetValue("initialDelay", task.InitialDelay); + schedule = CronExpression.Parse(configuration.GetValue("schedule", task.Schedule), CronFormat.IncludeSeconds); + var delaySeconds = configuration.GetValue("initialDelay", task.InitialDelay); + startupDelay = TimeSpan.FromSeconds(delaySeconds); enabled = configuration.GetValue("enabled", true); var degreeOfParallelism = configuration.GetValue("degreeOfParallelism", task.DegreeOfParallelism); diff --git a/src/EMBC.DFA/Services/GovBackgroundTask.cs b/src/EMBC.DFA/Services/GovBackgroundTask.cs index 892c455..cedc3fa 100644 --- a/src/EMBC.DFA/Services/GovBackgroundTask.cs +++ b/src/EMBC.DFA/Services/GovBackgroundTask.cs @@ -16,10 +16,7 @@ public class GovBackgroundTask : IBackgroundTask private readonly IIntakeManager _intakeManager; public string Schedule => "0 10-59/15 * * * *"; //Every 15 minutes, staggered by 10 minutes - public TimeSpan InitialDelay => TimeSpan.FromSeconds(30); - - public string TestSchedule => "40 * * * * *"; //every minute on second 40 - public TimeSpan FastDelay => TimeSpan.FromSeconds(3); + public int InitialDelay => 30; public int DegreeOfParallelism => 1; diff --git a/src/EMBC.DFA/Services/IndBackgroundTask.cs b/src/EMBC.DFA/Services/IndBackgroundTask.cs index 42ab611..e5a3736 100644 --- a/src/EMBC.DFA/Services/IndBackgroundTask.cs +++ b/src/EMBC.DFA/Services/IndBackgroundTask.cs @@ -16,10 +16,7 @@ public class IndBackgroundTask : IBackgroundTask private readonly IIntakeManager _intakeManager; public string Schedule => "0 5-59/15 * * * *"; //Every 15 minutes, staggered by 5 minutes - public TimeSpan InitialDelay => TimeSpan.FromSeconds(30); - - public string TestSchedule => "20 * * * * *"; //every minute on second 20 - public TimeSpan FastDelay => TimeSpan.FromSeconds(3); + public int InitialDelay => 30; public int DegreeOfParallelism => 1; diff --git a/src/EMBC.DFA/Services/SmbBackgroundTask.cs b/src/EMBC.DFA/Services/SmbBackgroundTask.cs index f33dd35..96722ec 100644 --- a/src/EMBC.DFA/Services/SmbBackgroundTask.cs +++ b/src/EMBC.DFA/Services/SmbBackgroundTask.cs @@ -16,10 +16,7 @@ public class SmbBackgroundTask : IBackgroundTask private readonly IIntakeManager _intakeManager; public string Schedule => "0 */15 * * * *"; //every 15 minutes - public TimeSpan InitialDelay => TimeSpan.FromSeconds(30); - - public string TestSchedule => "0 * * * * *"; //every minute on second 0 - public TimeSpan FastDelay => TimeSpan.FromSeconds(3); + public int InitialDelay => 30; public int DegreeOfParallelism => 1;