Beispiel #1
0
        public async Task WriteNewScheduleTargets()
        {
            // Decisions about whether the once-daily run target is near enough:

            if (await WasLastRunToday())
            {
                return;
            }

            // This will be an HHmm value such as 1030 or 2200; SchedulerQueue only invokes this
            // grain at 15-minute intervals, so quit unless we're near or past the run-at time.
            var paddedUtc    = todayUtc.PlusMinutes(5);
            var paddedTime   = paddedUtc.TimeOfDay;
            var runTargetUtc = await configCache.GetValue(ConstConfigKeys.ScheduleWriterRunTargetUtc);

            var(runHour, runMinute) = DateTimeAnalysis.GetHourMinute(runTargetUtc);
            if (paddedUtc.Date == todayUtc.Date && (paddedTime.Hour < runHour || (paddedTime.Hour == runHour && paddedTime.Minute < runMinute)))
            {
                return;
            }

            // Decision made: yes, write the next day's schedule records.
            logger.LogInformation($"WriteNewScheduleTargets");

            var jobs = await scheduleRepository.GetJobsWithScheduleSettings();

            if (jobs.Count == 0)
            {
                return;
            }

            foreach (var job in jobs)
            {
                try
                {
                    var planner      = new TargetPlanner(job, today.Plus(Duration.FromDays(1)), logger);
                    var newSchedules = planner.GetSchedules();

                    if (newSchedules.Count > 0)
                    {
                        await InsertScheduleRows(newSchedules);
                    }

                    newSchedules = null;
                }
                catch
                { }
            }

            await configRepository.UpdateConfig(ConstConfigKeys.ScheduleWriterLastRunDateUtc, InstantPattern.General.Format(today));
        }
Beispiel #2
0
        public async Task UpdateJobSchedules(string jobDefinitionId, bool removeExistingRows = true)
        {
            logger.LogInformation($"UpdateJobSchedules for job {jobDefinitionId}");

            bool wasLastRunToday = await WasLastRunToday();

            if (removeExistingRows)
            {
                await scheduleRepository.DeletePendingScheduledJobs(jobDefinitionId);
            }

            var job = await scheduleRepository.GetJobScheduleSettings(jobDefinitionId);

            try
            {
                var planner      = new TargetPlanner(job, today, logger);
                var newSchedules = planner.GetSchedules();

                // If we've already set up tomorrow's schedules (for all jobs)
                // do a second pass for this job targeting tomorrow's date.
                if (wasLastRunToday)
                {
                    planner = new TargetPlanner(job, today.Plus(Duration.FromDays(1)), logger);
                    newSchedules.AddRange(planner.GetSchedules());
                }

                if (newSchedules.Count > 0)
                {
                    await InsertScheduleRows(newSchedules);
                }

                newSchedules = null;
            }
            catch
            { }
        }