From b26daf4f67ec581dc42580d416ec041046356ab3 Mon Sep 17 00:00:00 2001 From: "Eric J. Smith" Date: Wed, 29 Nov 2023 18:07:50 -0600 Subject: [PATCH] Only use CRON if running all jobs --- src/Exceptionless.Job/JobRunnerOptions.cs | 3 +++ src/Exceptionless.Job/Program.cs | 22 ++++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/Exceptionless.Job/JobRunnerOptions.cs b/src/Exceptionless.Job/JobRunnerOptions.cs index 4110b24206..a8faf591e8 100644 --- a/src/Exceptionless.Job/JobRunnerOptions.cs +++ b/src/Exceptionless.Job/JobRunnerOptions.cs @@ -7,6 +7,8 @@ public JobRunnerOptions(string[] args) if (args.Length > 1) throw new ArgumentException("More than one job argument specified. You must either specify 1 named job or don't pass any arguments to run all jobs."); + AllJobs = args.Length == 0; + CleanupData = args.Length == 0 || args.Contains(nameof(CleanupData), StringComparer.OrdinalIgnoreCase); if (CleanupData && args.Length != 0) JobName = nameof(CleanupData); @@ -77,6 +79,7 @@ public JobRunnerOptions(string[] args) } public string JobName { get; } = "All"; + public bool AllJobs { get; } public bool CleanupData { get; } public bool CleanupOrphanedData { get; } public bool CloseInactiveSessions { get; } diff --git a/src/Exceptionless.Job/Program.cs b/src/Exceptionless.Job/Program.cs index d4a7f53355..5d25b1984d 100644 --- a/src/Exceptionless.Job/Program.cs +++ b/src/Exceptionless.Job/Program.cs @@ -135,18 +135,28 @@ private static void AddJobs(IServiceCollection services, JobRunnerOptions option { services.AddJobLifetimeService(); - if (options.CleanupData) + if (options is { CleanupData: true, AllJobs: true }) services.AddCronJob("30 */4 * * *"); - if (options.CleanupOrphanedData) + if (options is { CleanupData: true, AllJobs: false }) + services.AddJob(); + + if (options is { CleanupOrphanedData: true, AllJobs: true }) services.AddCronJob("45 */8 * * *"); + if (options is { CleanupOrphanedData: true, AllJobs: false }) + services.AddJob(); + if (options.CloseInactiveSessions) services.AddJob(true); if (options.DailySummary) services.AddJob(true); if (options.DataMigration) services.AddJob(true); - if (options.DownloadGeoIPDatabase) + + if (options is { DownloadGeoIPDatabase: true, AllJobs: true }) services.AddCronJob("0 1 * * *"); + if (options is { DownloadGeoIPDatabase: true, AllJobs: false }) + services.AddJob(true); + if (options.EventNotifications) services.AddJob(true); if (options.EventPosts) @@ -157,8 +167,12 @@ private static void AddJobs(IServiceCollection services, JobRunnerOptions option services.AddJob(true); if (options.MailMessage) services.AddJob(true); - if (options.MaintainIndexes) + + if (options is { MaintainIndexes: true, AllJobs: true }) services.AddCronJob("10 */2 * * *"); + if (options is { MaintainIndexes: true, AllJobs: false }) + services.AddJob(); + if (options.Migration) services.AddJob(true); if (options.StackStatus)