Skip to content

Commit

Permalink
Only use CRON if running all jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
ejsmith committed Nov 30, 2023
1 parent 65fdda9 commit b26daf4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/Exceptionless.Job/JobRunnerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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; }
Expand Down
22 changes: 18 additions & 4 deletions src/Exceptionless.Job/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CleanupDataJob>("30 */4 * * *");
if (options.CleanupOrphanedData)
if (options is { CleanupData: true, AllJobs: false })
services.AddJob<CleanupDataJob>();

if (options is { CleanupOrphanedData: true, AllJobs: true })
services.AddCronJob<CleanupOrphanedDataJob>("45 */8 * * *");
if (options is { CleanupOrphanedData: true, AllJobs: false })
services.AddJob<CleanupOrphanedDataJob>();

if (options.CloseInactiveSessions)
services.AddJob<CloseInactiveSessionsJob>(true);
if (options.DailySummary)
services.AddJob<DailySummaryJob>(true);
if (options.DataMigration)
services.AddJob<DataMigrationJob>(true);
if (options.DownloadGeoIPDatabase)

if (options is { DownloadGeoIPDatabase: true, AllJobs: true })
services.AddCronJob<DownloadGeoIPDatabaseJob>("0 1 * * *");
if (options is { DownloadGeoIPDatabase: true, AllJobs: false })
services.AddJob<DownloadGeoIPDatabaseJob>(true);

if (options.EventNotifications)
services.AddJob<EventNotificationsJob>(true);
if (options.EventPosts)
Expand All @@ -157,8 +167,12 @@ private static void AddJobs(IServiceCollection services, JobRunnerOptions option
services.AddJob<EventUserDescriptionsJob>(true);
if (options.MailMessage)
services.AddJob<MailMessageJob>(true);
if (options.MaintainIndexes)

if (options is { MaintainIndexes: true, AllJobs: true })
services.AddCronJob<MaintainIndexesJob>("10 */2 * * *");
if (options is { MaintainIndexes: true, AllJobs: false })
services.AddJob<MaintainIndexesJob>();

if (options.Migration)
services.AddJob<MigrationJob>(true);
if (options.StackStatus)
Expand Down

0 comments on commit b26daf4

Please sign in to comment.