private void ConfigureHangfire(IApplicationBuilder app) { if (!Configuration.GetValue <bool>(Constants.HangfireEnabled)) { return; } var dashboardOptions = new DashboardOptions { Authorization = new[] { new HangfireAuthorisationFilter(GetAdminRoleName()) }, DisplayStorageConnectionString = false, // Added to squash intermittent 'The required antiforgery cookie token must be provided' exceptions // Does not pose a significant attack vector as all jobs are essentially idempotent. IgnoreAntiforgeryToken = true }; app.UseHangfireDashboard("/hangfire", dashboardOptions); app.UseHangfireServer(new BackgroundJobServerOptions { WorkerCount = Configuration.GetValue <int>(Constants.HangfireWorkerCount) }); GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute { Attempts = 0 }); var scheduledJobConfig = new ScheduledJobsConfig(); Configuration.GetSection(Constants.ScheduledJobsConfig).Bind(scheduledJobConfig); HangfireJobScheduler.ScheduleRecurringJobs(scheduledJobConfig); }
private static void ConfigureHangfire(WebApplication app) { if (!app.Configuration.GetValue <bool>(Constants.HangfireEnabled)) { return; } var dashboardOptions = new DashboardOptions { Authorization = new[] { new HangfireAuthorisationFilter(app.Configuration.GetSection("AdOptions")["AdminUserGroup"]) }, DisplayStorageConnectionString = false, }; app.UseHangfireDashboard("/hangfire", dashboardOptions); GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute { Attempts = 0 }); var scheduledJobConfig = new ScheduledJobsConfig(); app.Configuration.GetSection(Constants.ScheduledJobsConfig).Bind(scheduledJobConfig); HangfireJobScheduler.ScheduleRecurringJobs(scheduledJobConfig); }
public static void ScheduleRecurringJobs(ScheduledJobsConfig scheduledJobsConfig) { if (scheduledJobsConfig.UserSyncEnabled) { RecurringJob.AddOrUpdate <UserSyncJob>( UserSyncJobId, job => job.Run(JobCancellationToken.Null), scheduledJobsConfig.UserSyncCron, TimeZoneInfo.Local); } else { RecurringJob.RemoveIfExists(UserSyncJobId); } if (scheduledJobsConfig.CloseInactiveNotificationsEnabled) { RecurringJob.AddOrUpdate <CloseInactiveNotificationsJob>( CloseInactiveNotificationsJobId, job => job.Run(JobCancellationToken.Null), scheduledJobsConfig.CloseInactiveNotificationsCron, TimeZoneInfo.Local); } else { RecurringJob.RemoveIfExists(CloseInactiveNotificationsJobId); } if (scheduledJobsConfig.DrugResistanceProfileUpdateEnabled) { RecurringJob.AddOrUpdate <DrugResistanceProfileUpdateJob>( DrugResistanceProfileUpdateJobId, job => job.Run(JobCancellationToken.Null), scheduledJobsConfig.DrugResistanceProfileUpdateCron, TimeZoneInfo.Local); } else { RecurringJob.RemoveIfExists(DrugResistanceProfileUpdateJobId); } if (scheduledJobsConfig.UnmatchedLabResultAlertsEnabled) { RecurringJob.AddOrUpdate <UnmatchedLabResultAlertsJob>( UnmatchedLabResultAlertsJobId, job => job.Run(JobCancellationToken.Null), scheduledJobsConfig.UnmatchedLabResultAlertsCron, TimeZoneInfo.Local); } else { RecurringJob.RemoveIfExists(UnmatchedLabResultAlertsJobId); } if (scheduledJobsConfig.DataQualityAlertsEnabled) { RecurringJob.AddOrUpdate <DataQualityAlertsJob>( DataQualityAlertsJobId, job => job.Run(JobCancellationToken.Null), scheduledJobsConfig.DataQualityAlertsCron, TimeZoneInfo.Local); } else { RecurringJob.RemoveIfExists(DataQualityAlertsJobId); } if (scheduledJobsConfig.NotificationClusterUpdateEnabled) { RecurringJob.AddOrUpdate <NotificationClusterUpdateJob>( NotificationClusterUpdateJobId, job => job.Run(JobCancellationToken.Null), scheduledJobsConfig.NotificationClusterUpdateCron, TimeZoneInfo.Local); } else { RecurringJob.RemoveIfExists(NotificationClusterUpdateJobId); } if (scheduledJobsConfig.MarkImportedNotificationsAsImportedEnabled) { RecurringJob.AddOrUpdate <MarkImportedNotificationsAsImportedJob>( MarkImportedNotificationsAsImportedJobId, job => job.Run(JobCancellationToken.Null), scheduledJobsConfig.MarkImportedNotificationsAsImportedCron, TimeZoneInfo.Local); } else { RecurringJob.RemoveIfExists(MarkImportedNotificationsAsImportedJobId); } }
public static void ScheduleRecurringJobs(ScheduledJobsConfig scheduledJobsConfig) { if (scheduledJobsConfig.UserSyncEnabled) { RecurringJob.AddOrUpdate <UserSyncJob>( UserSyncJobId, job => job.Run(JobCancellationToken.Null), scheduledJobsConfig.UserSyncCron, GmtStandardTime); } else { RecurringJob.RemoveIfExists(UserSyncJobId); } if (scheduledJobsConfig.CloseInactiveNotificationsEnabled) { RecurringJob.AddOrUpdate <CloseInactiveNotificationsJob>( CloseInactiveNotificationsJobId, job => job.Run(JobCancellationToken.Null), scheduledJobsConfig.CloseInactiveNotificationsCron, GmtStandardTime); } else { RecurringJob.RemoveIfExists(CloseInactiveNotificationsJobId); } if (scheduledJobsConfig.DrugResistanceProfileUpdateEnabled) { RecurringJob.AddOrUpdate <DrugResistanceProfileUpdateJob>( DrugResistanceProfileUpdateJobId, job => job.Run(JobCancellationToken.Null), scheduledJobsConfig.DrugResistanceProfileUpdateCron, GmtStandardTime); } else { RecurringJob.RemoveIfExists(DrugResistanceProfileUpdateJobId); } if (scheduledJobsConfig.UnmatchedLabResultAlertsEnabled) { RecurringJob.AddOrUpdate <UnmatchedLabResultAlertsJob>( UnmatchedLabResultAlertsJobId, job => job.Run(JobCancellationToken.Null), scheduledJobsConfig.UnmatchedLabResultAlertsCron, GmtStandardTime); } else { RecurringJob.RemoveIfExists(UnmatchedLabResultAlertsJobId); } if (scheduledJobsConfig.DataQualityAlertsEnabled) { RecurringJob.AddOrUpdate <DataQualityAlertsJob>( DataQualityAlertsJobId, job => job.Run(JobCancellationToken.Null), scheduledJobsConfig.DataQualityAlertsCron, GmtStandardTime); } else { RecurringJob.RemoveIfExists(DataQualityAlertsJobId); } if (scheduledJobsConfig.NotificationClusterUpdateEnabled) { RecurringJob.AddOrUpdate <NotificationClusterUpdateJob>( NotificationClusterUpdateJobId, job => job.Run(JobCancellationToken.Null), scheduledJobsConfig.NotificationClusterUpdateCron, GmtStandardTime); } else { RecurringJob.RemoveIfExists(NotificationClusterUpdateJobId); } if (scheduledJobsConfig.MarkImportedNotificationsAsImportedEnabled) { RecurringJob.AddOrUpdate <MarkImportedNotificationsAsImportedJob>( MarkImportedNotificationsAsImportedJobId, job => job.Run(JobCancellationToken.Null), scheduledJobsConfig.MarkImportedNotificationsAsImportedCron, GmtStandardTime); } else { RecurringJob.RemoveIfExists(MarkImportedNotificationsAsImportedJobId); } if (scheduledJobsConfig.GenerateReportingDataJobEnabled) { // PerformContext context is passed in via Hangfire Server RecurringJob.AddOrUpdate <GenerateReportingDataJob>( GenerateReportingDataJobId, job => job.Run(null), scheduledJobsConfig.GenerateReportingDataJobCron, GmtStandardTime); } else { RecurringJob.RemoveIfExists(GenerateReportingDataJobId); } if (scheduledJobsConfig.ReportingDataRefreshJobEnabled) { // PerformContext context is passed in via Hangfire Server RecurringJob.AddOrUpdate <ReportingDataRefreshJob>( ReportingDataRefreshJobId, job => job.Run(null), scheduledJobsConfig.ReportingDataRefreshJobCron, GmtStandardTime); } else { RecurringJob.RemoveIfExists(ReportingDataRefreshJobId); } if (scheduledJobsConfig.ReportingDataProcessingJobEnabled) { // PerformContext context is passed in via Hangfire Server RecurringJob.AddOrUpdate <ReportingDataProcessingJob>( ReportingDataProcessingJobId, job => job.Run(null), scheduledJobsConfig.ReportingDataProcessingJobCron, GmtStandardTime); } else { RecurringJob.RemoveIfExists(ReportingDataProcessingJobId); } if (scheduledJobsConfig.UpdateTableCountsJobEnabled) { // PerformContext context is passed in via Hangfire Server RecurringJob.AddOrUpdate <UpdateTableCountsJob>( UpdateTableCountsJobId, job => job.Run(null), scheduledJobsConfig.UpdateTableCountsJobCron, GmtStandardTime); } else { RecurringJob.RemoveIfExists(UpdateTableCountsJobId); } }