/// <summary>
        /// Set up the jobs particular to this application
        /// </summary>
        private static void ConfigureScheduledBackgroundJobs()
        {
            var recurringJobIds = new List <string>();

            // because the reminder configurations are tenant-specific and user-configurable, just schedule the job to run nightly and have it check whether it's time to send a remind for each tenant.
            AddRecurringJob(ProjectUpdateReminderScheduledBackgroundJob.JobName,
                            () => ScheduledBackgroundJobLaunchHelper.RunProjectUpdateKickoffReminderScheduledBackgroundJob(),
                            MakeDailyUtcCronJobStringFromLocalTime(1, 23),
                            recurringJobIds);

            // Clean up stale FirmaSessions
            AddRecurringJob(CleanUpStaleFirmaSessionsJob.JobName,
                            () => ScheduledBackgroundJobLaunchHelper.RunCleanUpStaleFirmaSessionsScheduledBackgroundJob(),
                            Cron.Hourly(10),
                            recurringJobIds);

            // Remove any jobs we haven't explicitly scheduled
            RemoveExtraneousJobs(recurringJobIds);
        }
Пример #2
0
        /*
         * /// <summary>
         * /// Set up the jobs particular to this application
         * /// </summary>
         * private static void ConfigureScheduledBackgroundJobs()
         * {
         *  var recurringJobIds = new List<string>();
         *
         *  // WADNR has the luxury of not worrying about tenant.
         *  // because the reminder configurations are tenant-specific and user-configurable, just schedule the job to run nightly and have it check whether it's time to send a remind for each tenant.
         *
         *  // Right now this job crashes, and we don't need it. Also, I can't get to Hangfire dashboard with /hangfire.
         *  // Ray suggests re-porting our Hangfire work from Gemini which doesn't auto-restore database and fire off jobs, so we may want to
         *  // just re-port all of Gemini Hangfire rather than debug what's here in Wadnr/Firma already. -- SLG 2/19/2019
         *
         *  AddRecurringJob(ProjectUpdateReminderScheduledBackgroundJob.JobName,
         *      () => ScheduledBackgroundJobLaunchHelper.RunProjectUpdateKickoffReminderScheduledBackgroundJob(),
         *      MakeDailyUtcCronJobStringFromLocalTime(1,23),
         *      recurringJobIds);
         *
         *  // Remove any jobs we haven't explicitly scheduled
         *  RemoveExtraneousJobs(recurringJobIds);
         * }
         */

        /// <summary>
        /// Set up the jobs particular to this application
        /// </summary>
        private static void ConfigureScheduledBackgroundJobs()
        {
            // Note that tasks here all have staggered start times - for example, all the hourly jobs start at 2, 4, 6, etc. minutes after the hour. This is to give the schedule a more
            // predictable flow, rather than starting random, less predictable traffic jams.
            var recurringJobIds = new List <string>();

            const int runJobEveryFifteenMinutes = 15;

            // Every 15 minutes jobs
            var cronValueFor15Minutes = CronValueOrNeverIfJobsDisabled($"*/{runJobEveryFifteenMinutes} * * * *");

            AddRecurringJob(VendorImportHangfireBackgroundJob.Instance.JobName, () => ScheduledBackgroundJobLaunchHelper.RunVendorImportScheduledBackgroundJob(JobCancellationToken.Null), cronValueFor15Minutes, recurringJobIds);
            AddRecurringJob(GrantExpenditureImportHangfireBackgroundJob.Instance.JobName, () => ScheduledBackgroundJobLaunchHelper.RunGrantExpenditureImportScheduledBackgroundJob(JobCancellationToken.Null), cronValueFor15Minutes, recurringJobIds);
            AddRecurringJob(ProjectCodeImportHangfireBackgroundJob.Instance.JobName, () => ScheduledBackgroundJobLaunchHelper.RunProjectCodeImportScheduledBackgroundJob(JobCancellationToken.Null), cronValueFor15Minutes, recurringJobIds);

            // We only add this job if we are beyond this date, so that can get to phase 2 without this job screaming at us.
            // This job (and likely others) needs a proper merge function, but we have no budget for this currently. -- SLG 7/9/2019
            const int yearToRestartProgramIndex     = 2019;
            const int monthToRestartProgramIndex    = 10;
            const int dayToRestartProgramIndex      = 1;
            const int hourToRestartProgramIndex     = 11;
            var       dateTimeToRestartProgramIndex = new DateTime(yearToRestartProgramIndex, monthToRestartProgramIndex, dayToRestartProgramIndex, hourToRestartProgramIndex, 0, 0);

            if (DateTime.Now >= dateTimeToRestartProgramIndex)
            {
                AddRecurringJob(ProgramIndexImportHangfireBackgroundJob.Instance.JobName, () => ScheduledBackgroundJobLaunchHelper.RunProgramIndexImportScheduledBackgroundJob(JobCancellationToken.Null), cronValueFor15Minutes, recurringJobIds);
            }

            // 1:30 AM tasks
            //var oneThirtyAmCronString = MakeDailyCronJobStringFromLocalTime(1, 36);


            // See ConfigureScheduledBackgroundJobs in Gemini for further examples of how to schedule things at various time intervals.
            // Commented out examples below.

            /*
             * AddRecurringJob(WorkflowNotificationsScheduledBackgroundJob.Instance.JobName, () => ScheduledBackgroundJobLaunchHelper.RunWorkflowNotificationsScheduledBackgroundJob(JobCancellationToken.Null), CronValueOrNeverIfJobsDisabled(Cron.Hourly(2)), recurringJobIds);
             * AddRecurringJob(ChangeRequestMeetingScheduledBackgroundJob.Instance.JobName, () => ScheduledBackgroundJobLaunchHelper.RunChangeRequestMeetingScheduledBackgroundJob(JobCancellationToken.Null), CronValueOrNeverIfJobsDisabled(Cron.Hourly(4)), recurringJobIds);
             * AddRecurringJob(TaurusSessionDeletedExpiredScheduledBackgroundJob.Instance.JobName, () => ScheduledBackgroundJobLaunchHelper.RunTaurusSessionDeletedExpiredScheduledBackgroundJob(JobCancellationToken.Null), CronValueOrNeverIfJobsDisabled(Cron.Hourly(6)), recurringJobIds);
             * AddRecurringJob(SnapshotPortfolioReviewBackgroundJob.Instance.JobName, () => ScheduledBackgroundJobLaunchHelper.RunSnapshotPortfolioReviewBackgroundJob(JobCancellationToken.Null), CronValueOrNeverIfJobsDisabled(Cron.Hourly(8)), recurringJobIds);
             *
             * // 11:00~ish PM tasks
             * AddRecurringJob(BudgetStartOfYearSendDigestNotificationBackgroundJob.Instance.JobName, () => ScheduledBackgroundJobLaunchHelper.RunBudgetStartOfYearSendDigestNotificationBackgroundJob(JobCancellationToken.Null), CronValueOrNeverIfJobsDisabled(MakeDailyCronJobStringFromLocalTime(23, 00)), recurringJobIds);
             * AddRecurringJob(ProjectSendDigestNotificationTaurusBackgroundJob.Instance.JobName, () => ScheduledBackgroundJobLaunchHelper.RunProjectSendDigestNotificationTaurusBackgroundJob(JobCancellationToken.Null), CronValueOrNeverIfJobsDisabled(MakeDailyCronJobStringFromLocalTime(23, 05)), recurringJobIds);
             */


            //// 12:05 am tasks
            //// This job takes a while ideally it will be done before the Aries ETL processes.
            //// Also we don't want it to run during the 11:30pm time because that's when there's a nightly web site reset.
            //AddRecurringJob(IdentifyXYScheduledBackgroundJob.Instance.JobName, () => ScheduledBackgroundJobLaunchHelper.RunIdentifyXYScheduledBackgroundJob(JobCancellationToken.Null), CronValueOrNeverIfJobsDisabled(MakeDailyCronJobStringFromLocalTime(00, 05)), recurringJobIds);

            //// 1:30~ish AM tasks
            //AddRecurringJob(SessionCleanupScheduledBackgroundJob.Instance.JobName, () => ScheduledBackgroundJobLaunchHelper.RunSessionCleanupScheduledBackgroundJob(JobCancellationToken.Null), CronValueOrNeverIfJobsDisabled(MakeDailyCronJobStringFromLocalTime(1, 36)), recurringJobIds);

            //// 2:00~ish AM tasks
            //AddRecurringJob(UpdateMonitoringResourcesWebReferencePaths.Instance.JobName, () => ScheduledBackgroundJobLaunchHelper.RunUpdateMonitoringResourcesWebReferencePaths(JobCancellationToken.Null), CronValueOrNeverIfJobsDisabled(MakeDailyCronJobStringFromLocalTime(2, 03)), recurringJobIds);
            //AddRecurringJob(CleanUpOgr2OgrFilesAndDatabaseTables.Instance.JobName, () => ScheduledBackgroundJobLaunchHelper.RunCleanUpOgr2OgrFilesAndDatabaseTables(JobCancellationToken.Null), CronValueOrNeverIfJobsDisabled(MakeDailyCronJobStringFromLocalTime(2, 10)), recurringJobIds);

            //// 4:30~ish AM tasks
            //AddRecurringJob(FireRemindersScheduledBackgroundJob.Instance.JobName, () => ScheduledBackgroundJobLaunchHelper.RunFireRemindersScheduledBackgroundJob(JobCancellationToken.Null), CronValueOrNeverIfJobsDisabled(MakeDailyCronJobStringFromLocalTime(4, 30)), recurringJobIds);
            //AddRecurringJob(AccrualObligationsScheduledBackgroundJob.Instance.JobName, () => ScheduledBackgroundJobLaunchHelper.RunAccrualObligationsScheduledBackgroundJob(JobCancellationToken.Null), CronValueOrNeverIfJobsDisabled(MakeDailyCronJobStringFromLocalTime(4, 35)), recurringJobIds);
            //AddRecurringJob(StatusReportStatisticsScheduledBackgroundJob.Instance.JobName, () => ScheduledBackgroundJobLaunchHelper.RunStatusReportStatisticsScheduledBackgroundJob(JobCancellationToken.Null), CronValueOrNeverIfJobsDisabled(MakeDailyCronJobStringFromLocalTime(4, 40)), recurringJobIds);
            //AddRecurringJob(AutoSetTaskStatusScheduledBackgroundJob.Instance.JobName, () => ScheduledBackgroundJobLaunchHelper.RunAutoSetTaskStatusScheduledBackgroundJob(JobCancellationToken.Null), CronValueOrNeverIfJobsDisabled(MakeDailyCronJobStringFromLocalTime(4, 45)), recurringJobIds);

            //// 6:00~ish AM tasks
            //AddRecurringJob(DeleteOldPortfolioCacheRecordsScheduledBackgroundJob.Instance.JobName, () => ScheduledBackgroundJobLaunchHelper.RunDeleteOldPortfolioCacheRecordsScheduledBackgroundJob(JobCancellationToken.Null), CronValueOrNeverIfJobsDisabled(MakeDailyCronJobStringFromLocalTime(5, 55)), recurringJobIds);
            //AddRecurringJob(MailDataQualityAdminScheduledBackgroundJob.Instance.JobName, () => ScheduledBackgroundJobLaunchHelper.RunMailDataQualityAdminScheduledBackgroundJob(JobCancellationToken.Null), CronValueOrNeverIfJobsDisabled(MakeDailyCronJobStringFromLocalTime(6, 00)), recurringJobIds);
            //AddRecurringJob(UpdatePortfolioCacheTaurusBackgroundJob.Instance.JobName, () => ScheduledBackgroundJobLaunchHelper.RunUpdatePortfolioCacheTaurusBackgroundJob(JobCancellationToken.Null), CronValueOrNeverIfJobsDisabled(MakeDailyCronJobStringFromLocalTime(6, 05)), recurringJobIds);
            //AddRecurringJob(CostSharePlanReminderEmailBackgroundJob.Instance.JobName, () => ScheduledBackgroundJobLaunchHelper.RunCostSharePlanReminderEmailBackgroundJob(JobCancellationToken.Null), CronValueOrNeverIfJobsDisabled(MakeDailyCronJobStringFromLocalTime(6, 30)), recurringJobIds);

            //// every 5 minutes jobs
            //AddRecurringJob(UpdateDocumentIndexScheduledBackgroundJob.Instance.JobName, () => ScheduledBackgroundJobLaunchHelper.RunUpdateDocumentIndexScheduledBackgroundJob(JobCancellationToken.Null), CronValueOrNeverIfJobsDisabled("*/5 * * * *"), recurringJobIds);
            //AddRecurringJob(NotifyAboutNewUserAgentsThatMightBeUnwantedBots.Instance.JobName, () => ScheduledBackgroundJobLaunchHelper.RunNotifyAboutNewUserAgentsThatMightBeUnwantedBotsBackgroundJob(JobCancellationToken.Null), CronValueOrNeverIfJobsDisabled("*/5 * * * *"), recurringJobIds);

            //// every 15 minutes jobs
            //AddRecurringJob(VirusScanScheduledBackgroundJob.Instance.JobName, () => ScheduledBackgroundJobLaunchHelper.RunVirusScanScheduledBackgroundJob(JobCancellationToken.Null), CronValueOrNeverIfJobsDisabled($"*/{VirusScanScheduledBackgroundJob.RunJobEveryNMinutes} * * * *"), recurringJobIds);
            //AddRecurringJob(GenerateFilesForDownloadScheduledBackgroundJob.Instance.JobName, () => ScheduledBackgroundJobLaunchHelper.RunGenerateFilesForDownloadScheduledBackgroundJobBackgroundJob(JobCancellationToken.Null), CronValueOrNeverIfJobsDisabled("*/15 * * * *"), recurringJobIds);


            //// every 2 hour jobs
            //AddRecurringJob(UpdateMonitoringResourcesCache.Instance.JobName, () => ScheduledBackgroundJobLaunchHelper.RunUpdateMonitoringResourcesCache(JobCancellationToken.Null), CronValueOrNeverIfJobsDisabled(MakeDailyCronJobStringForMinuteWithOffset(11, 120)), recurringJobIds);

            // Remove any jobs we haven't explicitly scheduled above
            RemoveExtraneousJobs(recurringJobIds);
        }