Skip to content

Commit

Permalink
Merge pull request #52 from josephweinkam/main
Browse files Browse the repository at this point in the history
background task scheduling clean up
  • Loading branch information
josephweinkamgov authored Mar 24, 2023
2 parents cfd4dbb + 147c2d3 commit 8b07355
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 19 deletions.
11 changes: 4 additions & 7 deletions src/EMBC.DFA/Services/BackgroundTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -44,10 +42,9 @@ public BackgroundTask(IServiceProvider serviceProvider, IDistributedSemaphorePro
var task = scope.ServiceProvider.GetRequiredService<T>();
var appName = Environment.GetEnvironmentVariable("APP_NAME") ?? Assembly.GetEntryAssembly()?.GetName().Name ?? string.Empty;

var scheduleToUse = serviceProvider.GetRequiredService<IConfiguration>().GetValue("USE_TEST_SCHEDULE", false) ? task.TestSchedule : task.Schedule;

schedule = CronExpression.Parse(configuration.GetValue("schedule", scheduleToUse), CronFormat.IncludeSeconds);
startupDelay = serviceProvider.GetRequiredService<IConfiguration>().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);

Expand Down
5 changes: 1 addition & 4 deletions src/EMBC.DFA/Services/GovBackgroundTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 1 addition & 4 deletions src/EMBC.DFA/Services/IndBackgroundTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 1 addition & 4 deletions src/EMBC.DFA/Services/SmbBackgroundTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 8b07355

Please sign in to comment.