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 override async Task OnActivateAsync()
 {
     scheduleWriter   = GrainFactory.GetGrain <IScheduleWriter>();
     maxJobAssignment = int.Parse(await configCache.GetValue(ConstConfigKeys.SchedulerQueueMaxJobAssignment));
     await base.OnActivateAsync();
 }