internal void CheckSchedules(SchedulerInstance instance)
        {
            lock (repoLocker)
            {
                if (crontab == null)
                {
                    var cronEntries = repo.GetAll();
                    crontab = cronEntries.Select(x => Tuple.Create(x, CrontabSchedule.Parse(x.Cron))).ToList();
                    log.Info(crontab.Count + " Cron elements loaded");
                }
                if (crontab.Count > 0)
                {
                    var currentTime = DateTime.Now;
                    try
                    {
                        foreach (var tuple in crontab)
                        {
                            if (tuple.Item2.GetNextOccurrence(tuple.Item1.LastSchedule) < currentTime)
                            {
                                log.Info(String.Format("Scheduling {0} ({1})",
                                                       tuple.Item1.TaskName, tuple.Item1.Cron));
                                instance.Schedule(tuple.Item1.TaskName, tuple.Item1.Parallelism);

                                tuple.Item1.LastSchedule = currentTime;
                                repo.Update(tuple.Item1);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Error("Error checking schedules", ex);
                    }
                }
            }
        }
 public SchedulerInstance(ILog log, 
     RecurrencyController recurrencyController,
     ScheduleRepository repo, int workers = 5)
 {
     if (Instance != null) throw new InvalidOperationException("Scheduler already initialized");
     workersAmount = workers;
     this.log = log;
     this.recurrencyController = recurrencyController;
     this.repo = repo;
     Instance = this;
 }
예제 #3
0
 public SchedulerInstance(ILog log,
                          RecurrencyController recurrencyController,
                          ScheduleRepository repo, int workers = 5)
 {
     if (Instance != null)
     {
         throw new InvalidOperationException("Scheduler already initialized");
     }
     workersAmount             = workers;
     this.log                  = log;
     this.recurrencyController = recurrencyController;
     this.repo                 = repo;
     Instance                  = this;
 }
        public SchedulerServiceTracker(SchedulerInstance schedulerInstance, IComponentContext context)
        {
            _schedulerInstance = schedulerInstance;
            _context = context;

        }
        internal void CheckSchedules(SchedulerInstance instance)
        {
            lock (repoLocker)
            {
                if (crontab == null)
                {
                    var cronEntries = repo.GetAll();
                    crontab = cronEntries.Select(x => Tuple.Create(x, CrontabSchedule.Parse(x.Cron))).ToList();
                    log.Info(crontab.Count + " Cron elements loaded");
                }
                if (crontab.Count > 0)
                {
                    var currentTime = DateTime.Now;
                    try
                    {
                        foreach (var tuple in crontab)
                        {
                            if (tuple.Item2.GetNextOccurrence(tuple.Item1.LastSchedule) < currentTime)
                            {
                                log.Info(String.Format("Scheduling {0} ({1})",
                                    tuple.Item1.TaskName, tuple.Item1.Cron));
                                instance.Schedule(tuple.Item1.TaskName, tuple.Item1.Parallelism);

                                tuple.Item1.LastSchedule = currentTime;
                                repo.Update(tuple.Item1);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Error("Error checking schedules", ex);
                    }
                }
            }
        }
예제 #6
0
 public static void InitComponents()
 {
     ScheduleInstance = Bootstrap.Container.Resolve<SchedulerInstance>();
     ScheduleInstance.Start(Bootstrap.Container);
     log.Debug("Components initialized");
 }