Пример #1
0
        public Task Execute(IJobExecutionContext context)
        {
            // get the from and to dates
            DateTime from = context.PreviousFireTimeUtc.HasValue ? context.PreviousFireTimeUtc.Value.LocalDateTime : DateTime.Now.AddMinutes(-5);
            DateTime to   = context.FireTimeUtc.LocalDateTime;

            List <Trigger> triggers = new();

            // calculate all the triggers
            foreach (var trigger in jsonDatabaseService.ScheduledTriggers)
            {
                DateTime calculatedTime = CalculateTriggerTime(trigger.At, trigger.Mode);
                if (calculatedTime > from && to >= calculatedTime)
                {
                    triggers.Add(trigger);
                }
            }

            // fire all found triggers
            if (triggers.Any())
            {
                return(triggerService.FireTriggers(triggers));
            }

            return(Task.CompletedTask);
        }