예제 #1
0
        public void GetNextOccurrence_NowEqualToNext_ReturnsCorrectValue()
        {
            CronSchedule schedule = new CronSchedule("0 * * * * *");

            var now  = schedule.GetNextOccurrence(DateTime.Now);
            var next = schedule.GetNextOccurrence(now);

            Assert.True(next > now);
        }
예제 #2
0
        public void Create_CronSchedule_CreatesExpectedSchedule()
        {
            TimerTriggerAttribute attribute    = new TimerTriggerAttribute("*/15 * * * * *");
            INameResolver         nameResolver = new TestNameResolver();
            CronSchedule          schedule     = (CronSchedule)TimerSchedule.Create(attribute, nameResolver);

            Assert.False(attribute.UseMonitor);

            DateTime now            = new DateTime(2015, 5, 22, 9, 45, 00);
            DateTime nextOccurrence = schedule.GetNextOccurrence(now);

            Assert.Equal(new TimeSpan(0, 0, 15), nextOccurrence - now);

            // For schedules occuring on an interval greater than a minute, we expect
            // UseMonitor to be defaulted to true
            attribute = new TimerTriggerAttribute("0 0 * * * *");
            schedule  = (CronSchedule)TimerSchedule.Create(attribute, nameResolver);
            Assert.True(attribute.UseMonitor);

            // verify that if UseMonitor is set explicitly, it is not overridden
            attribute            = new TimerTriggerAttribute("0 0 * * * *");
            attribute.UseMonitor = false;
            schedule             = (CronSchedule)TimerSchedule.Create(attribute, nameResolver);
            Assert.False(attribute.UseMonitor);
        }
        public void Create_CronSchedule_CreatesExpectedSchedule()
        {
            TimerTriggerAttribute attribute    = new TimerTriggerAttribute("*/15 * * * * *");
            INameResolver         nameResolver = new TestNameResolver();
            CronSchedule          schedule     = (CronSchedule)TimerSchedule.Create(attribute, nameResolver, _logger);

            Assert.False(attribute.UseMonitor);
            var log = _loggerProvider.GetAllLogMessages().Single();

            Assert.Equal("UseMonitor changed to false based on schedule frequency.", log.FormattedMessage);
            Assert.Equal(LogLevel.Debug, log.Level);

            DateTime now            = new DateTime(2015, 5, 22, 9, 45, 00);
            DateTime nextOccurrence = schedule.GetNextOccurrence(now);

            Assert.Equal(new TimeSpan(0, 0, 15), nextOccurrence - now);

            // For schedules occuring on an interval greater than a minute, we expect
            // UseMonitor to be defaulted to true
            _loggerProvider.ClearAllLogMessages();
            attribute = new TimerTriggerAttribute("0 0 * * * *");
            schedule  = (CronSchedule)TimerSchedule.Create(attribute, nameResolver, _logger);
            Assert.True(attribute.UseMonitor);
            Assert.Empty(_loggerProvider.GetAllLogMessages());

            // verify that if UseMonitor is set explicitly, it is not overridden
            _loggerProvider.ClearAllLogMessages();
            attribute            = new TimerTriggerAttribute("0 0 * * * *");
            attribute.UseMonitor = false;
            schedule             = (CronSchedule)TimerSchedule.Create(attribute, nameResolver, _logger);
            Assert.False(attribute.UseMonitor);
            Assert.Empty(_loggerProvider.GetAllLogMessages());
        }
예제 #4
0
        public void Create_UsesNameResolver()
        {
            TimerTriggerAttribute attribute    = new TimerTriggerAttribute("%test_schedule%");
            TestNameResolver      nameResolver = new TestNameResolver();

            nameResolver.Values.Add("test_schedule", "*/15 * * * * *");
            CronSchedule schedule = (CronSchedule)TimerSchedule.Create(attribute, nameResolver);

            Assert.False(attribute.UseMonitor);

            DateTime now            = new DateTime(2015, 5, 22, 9, 45, 00);
            DateTime nextOccurrence = schedule.GetNextOccurrence(now);

            Assert.Equal(new TimeSpan(0, 0, 15), nextOccurrence - now);
        }
예제 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="now"></param>
        /// <returns></returns>
        public override DateTime GetNextOccurrence(DateTime now)
        {
            //A neat site to help figure out cron expressions - just remember that azure expects a seconds value to be first
            //http://crontab.guru/#*_*_*_*_*

            //says run every fiftenn minutes from 6pm to 6am i.e. off business hours
            //"0 0/15 0,1,2,3,4,5,6,18,19,20,21,22,23 * * *"

            //says run every 20 seconds
            //"0/20 * * * * *"

            var instance = new CronSchedule(this.AppSettings.SevisCommCronSchedule);

            return(instance.GetNextOccurrence(now));
        }
예제 #6
0
        public void GetNextOccurrence_ThreeDaySchedule_MultipleScheduleIterations()
        {
            // 11:59AM on Mondays, Tuesdays, Wednesdays, Thursdays and Fridays
            CronSchedule schedule = new CronSchedule("0 59 11 * * 1-5");

            DateTime now = new DateTime(2015, 5, 23, 9, 0, 0);

            TimeSpan expectedTime = new TimeSpan(11, 59, 0);

            for (int i = 1; i <= 5; i++)
            {
                DateTime nextOccurrence = schedule.GetNextOccurrence(now);

                Assert.Equal((DayOfWeek)i, nextOccurrence.DayOfWeek);
                Assert.Equal(expectedTime, nextOccurrence.TimeOfDay);
                now = nextOccurrence + TimeSpan.FromSeconds(1);
            }
        }