Esempio n. 1
0
        public ValidationResult Run()
        {
            var scrapingCronSchedule = Environment.GetEnvironmentVariable(EnvironmentVariables.Scraping.CronSchedule);

            if (string.IsNullOrWhiteSpace(scrapingCronSchedule))
            {
                LogMessage(
                    $"No scraping schedule was specified, falling back to default '{DefaultCronSchedule}' cron schedule...");
                scrapingCronSchedule = DefaultCronSchedule;
                Environment.SetEnvironmentVariable(EnvironmentVariables.Scraping.CronSchedule, scrapingCronSchedule);
            }

            try
            {
                CronSchedule.Parse(scrapingCronSchedule);
                return(ValidationResult.Successful(ComponentName));
            }
            catch (Exception exception)
            {
                LogMessage(
                    $"No valid scraping schedule was specified - '{scrapingCronSchedule}'. Details: {exception.Message}");
                return(ValidationResult.Failure(ComponentName,
                                                $"No valid scraping schedule was specified - '{scrapingCronSchedule}'."));
            }
        }
Esempio n. 2
0
 private DateTime?GetNextDateTime()
 {
     try
     {
         DateTime nextTime;
         var      cs = CronSchedule.Parse(Expression);
         cs.GetNext(DateTime.Now, out nextTime);
         return(nextTime);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Esempio n. 3
0
        public SchedulerHostedService(IEnumerable <IScheduledTask> scheduledTasks)
        {
            var referenceTime = DateTime.UtcNow;

            foreach (var scheduledTask in scheduledTasks)
            {
                _scheduledTasks.Add(new SchedulerTaskWrapper
                {
                    Schedule    = CronSchedule.Parse(scheduledTask.Schedule),
                    Task        = scheduledTask,
                    NextRunTime = referenceTime
                });
            }
        }
Esempio n. 4
0
        public void UpdateCronObjects()
        {
            CloseTriggers();

            var triggers = Dao.Query <Trigger>();

            foreach (var trigger in triggers)
            {
                var dataContext = new CronObjectDataContext(new List <CronSchedule> {
                    CronSchedule.Parse(trigger.Expression)
                })
                {
                    Object      = trigger,
                    LastTrigger = trigger.LastTrigger
                };

                var cronObject = new CronObject(dataContext);
                cronObject.OnCronTrigger += OnCronTrigger;
                _cronObjects.Add(cronObject);
            }
            _cronObjects.ForEach(x => x.Start());
        }
        public ValidationResult Run()
        {
            var scrapingCronSchedule = Environment.GetEnvironmentVariable(EnvironmentVariables.Scraping.CronSchedule);

            if (string.IsNullOrWhiteSpace(scrapingCronSchedule))
            {
                Logger.LogWarning("No scraping schedule was specified, falling back to default '{ScrapeSchedule}' cron schedule...", DefaultCronSchedule);
                scrapingCronSchedule = DefaultCronSchedule;
                Environment.SetEnvironmentVariable(EnvironmentVariables.Scraping.CronSchedule, scrapingCronSchedule);
            }

            try
            {
                CronSchedule.Parse(scrapingCronSchedule);
                return(ValidationResult.Successful(ComponentName));
            }
            catch (Exception exception)
            {
                Logger.LogError("No valid scraping schedule was specified ('{ScrapeSchedule}' - Exception: {Exception})", DefaultCronSchedule, exception);
                return(ValidationResult.Failure(ComponentName, $"No valid scraping schedule was specified - '{scrapingCronSchedule}'."));
            }
        }
Esempio n. 6
0
        private CronObject CreateCronObject(Type newTaskType, string groupName, string cronExpression)
        {
            var cronSchedule  = CronSchedule.Parse(cronExpression);
            var cronSchedules = new List <CronSchedule> {
                cronSchedule
            };

            var dc = new CronObjectDataContext
            {
                Object = new CronObjectHelper()
                {
                    TaskType = newTaskType, GroupName = groupName
                },
                CronSchedules = cronSchedules,
                LastTrigger   = DateTime.Now
            };

            var cron = new CronObject(dc);

            cron.OnCronTrigger += Cron_OnCronTrigger;
            cron.OnThreadAbort += Cron_OnThreadAbort;
            return(cron);
        }