本文整理汇总了Python中apscheduler.triggers.cron.CronTrigger类的典型用法代码示例。如果您正苦于以下问题:Python CronTrigger类的具体用法?Python CronTrigger怎么用?Python CronTrigger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CronTrigger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cron_trigger_4
def test_cron_trigger_4(self, timezone):
trigger = CronTrigger(year='2012', month='2', day='last', timezone=timezone)
assert repr(trigger) == ("<CronTrigger (year='2012', month='2', day='last', "
"timezone='Europe/Berlin')>")
start_date = timezone.localize(datetime(2012, 2, 1))
correct_next_date = timezone.localize(datetime(2012, 2, 29))
assert trigger.get_next_fire_time(None, start_date) == correct_next_date
示例2: test_cron_trigger_3
def test_cron_trigger_3(self, timezone):
trigger = CronTrigger(year='2009', month='2', hour='8-10', timezone=timezone)
assert repr(trigger) == ("<CronTrigger (year='2009', month='2', hour='8-10', "
"timezone='Europe/Berlin')>")
start_date = timezone.localize(datetime(2009, 1, 1))
correct_next_date = timezone.localize(datetime(2009, 2, 1, 8))
assert trigger.get_next_fire_time(None, start_date) == correct_next_date
示例3: test_cron_trigger_1
def test_cron_trigger_1(self, timezone):
trigger = CronTrigger(year="2009/2", month="1/3", day="5-13", timezone=timezone)
assert repr(trigger) == "<CronTrigger (year='2009/2', month='1/3', day='5-13')>"
assert str(trigger) == "cron[year='2009/2', month='1/3', day='5-13']"
start_date = timezone.localize(datetime(2008, 12, 1))
correct_next_date = timezone.localize(datetime(2009, 1, 5))
assert trigger.get_next_fire_time(None, start_date) == correct_next_date
示例4: test_week_1
def test_week_1(self, timezone):
trigger = CronTrigger(year=2009, month=2, week=8, timezone=timezone)
assert repr(trigger) == "<CronTrigger (year='2009', month='2', week='8')>"
assert str(trigger) == "cron[year='2009', month='2', week='8']"
start_date = timezone.localize(datetime(2009, 1, 1))
correct_next_date = timezone.localize(datetime(2009, 2, 16))
assert trigger.get_next_fire_time(None, start_date) == correct_next_date
示例5: test_week_2
def test_week_2(self, timezone):
trigger = CronTrigger(year=2009, week=15, day_of_week=2, timezone=timezone)
assert repr(trigger) == "<CronTrigger (year='2009', week='15', day_of_week='2')>"
assert str(trigger) == "cron[year='2009', week='15', day_of_week='2']"
start_date = timezone.localize(datetime(2009, 1, 1))
correct_next_date = timezone.localize(datetime(2009, 4, 8))
assert trigger.get_next_fire_time(None, start_date) == correct_next_date
示例6: test_cron_year_list
def test_cron_year_list(self, timezone):
trigger = CronTrigger(year='2009,2008', timezone=timezone)
assert repr(trigger) == "<CronTrigger (year='2009,2008', timezone='Europe/Berlin')>"
assert str(trigger) == "cron[year='2009,2008']"
start_date = timezone.localize(datetime(2009, 1, 1))
correct_next_date = timezone.localize(datetime(2009, 1, 1))
assert trigger.get_next_fire_time(None, start_date) == correct_next_date
示例7: add_random_tasks
def add_random_tasks(self, module_name, cls_name, function_name, start_hour, end_hour, day_of_week, num_times_per_day, ignore_scheduler_lock=False):
# This function is fired at startup, and every day at midnight.
if end_hour < start_hour:
raise Exception("start_hour is after end_hour!")
# Get the next appropriate date
now = datetime.datetime.now()
# Work around crontab bug where if the hour has started, it's skipped.
adjusted_start_hour = start_hour
if adjusted_start_hour != 23:
adjusted_start_hour += 1
adjusted_start_hour = "%s" % adjusted_start_hour
ct = CronTrigger(hour=adjusted_start_hour, day_of_week=day_of_week)
fire_time = ct.get_next_fire_time(now)
# If it's today, schedule it. Otherwise, it'll be scheduled at midnight of its run day.
if fire_time.day == now.day:
# There are more efficient ways to do this, but this supports almost any n for num_times_per_day,
# and that seems more useful.
possible_times = []
for i in range(start_hour, end_hour):
for j in range(60):
possible_times.append((i,j))
times = random.sample(possible_times, num_times_per_day)
for hour, minute in times:
when = datetime.datetime(now.year, now.month, now.day, hour, minute)
# If we're starting up mid-day, this may not be true.
if when >= now:
self.add_single_random_task(when, module_name, cls_name, function_name, start_hour, end_hour, day_of_week, num_times_per_day, ignore_scheduler_lock=ignore_scheduler_lock)
示例8: test_previous_fire_time_1
def test_previous_fire_time_1(self, timezone):
"""Test for previous_fire_time arg in get_next_fire_time()"""
trigger = CronTrigger(day="*", timezone=timezone)
previous_fire_time = timezone.localize(datetime(2015, 11, 23))
now = timezone.localize(datetime(2015, 11, 26))
correct_next_date = timezone.localize(datetime(2015, 11, 24))
assert trigger.get_next_fire_time(previous_fire_time, now) == correct_next_date
示例9: test_cron_weekday_nomatch
def test_cron_weekday_nomatch(self, timezone):
trigger = CronTrigger(year=2009, month=1, day="6-10", day_of_week="0,6", timezone=timezone)
assert repr(trigger) == "<CronTrigger (year='2009', month='1', day='6-10', day_of_week='0,6')>"
assert str(trigger) == "cron[year='2009', month='1', day='6-10', day_of_week='0,6']"
start_date = timezone.localize(datetime(2009, 1, 1))
correct_next_date = None
assert trigger.get_next_fire_time(None, start_date) == correct_next_date
示例10: test_cron_weekday_positional
def test_cron_weekday_positional(self, timezone):
trigger = CronTrigger(year=2009, month=1, day="4th wed", timezone=timezone)
assert repr(trigger) == "<CronTrigger (year='2009', month='1', day='4th wed')>"
assert str(trigger) == "cron[year='2009', month='1', day='4th wed']"
start_date = timezone.localize(datetime(2009, 1, 1))
correct_next_date = timezone.localize(datetime(2009, 1, 28))
assert trigger.get_next_fire_time(None, start_date) == correct_next_date
示例11: test_different_tz
def test_different_tz(self, timezone):
alter_tz = pytz.FixedOffset(-600)
trigger = CronTrigger(year=2009, week=15, day_of_week=2, timezone=timezone)
assert repr(trigger) == "<CronTrigger (year='2009', week='15', day_of_week='2')>"
assert str(trigger) == "cron[year='2009', week='15', day_of_week='2']"
start_date = alter_tz.localize(datetime(2008, 12, 31, 22))
correct_next_date = timezone.localize(datetime(2009, 4, 8))
assert trigger.get_next_fire_time(None, start_date) == correct_next_date
示例12: test_cron_weekday_overlap
def test_cron_weekday_overlap(self, timezone):
trigger = CronTrigger(year=2009, month=1, day='6-10', day_of_week='2-4', timezone=timezone)
assert repr(trigger) == ("<CronTrigger (year='2009', month='1', day='6-10', "
"day_of_week='2-4', timezone='Europe/Berlin')>")
assert str(trigger) == "cron[year='2009', month='1', day='6-10', day_of_week='2-4']"
start_date = timezone.localize(datetime(2009, 1, 1))
correct_next_date = timezone.localize(datetime(2009, 1, 7))
assert trigger.get_next_fire_time(None, start_date) == correct_next_date
示例13: test_end_date
def test_end_date(self, timezone):
end_date = timezone.localize(datetime(2014, 4, 13, 3))
trigger = CronTrigger(year=2014, hour=4, end_date=end_date)
start_date = timezone.localize(datetime(2014, 4, 13, 2, 30))
assert trigger.get_next_fire_time(None, start_date - timedelta(1)) == \
start_date.replace(day=12, hour=4, minute=0)
assert trigger.get_next_fire_time(None, start_date) is None
示例14: test_cron_start_date
def test_cron_start_date(self, timezone):
trigger = CronTrigger(year='2009', month='2', hour='8-10', start_date='2009-02-03 11:00:00', timezone=timezone)
assert repr(trigger) == \
"<CronTrigger (year='2009', month='2', hour='8-10', start_date='2009-02-03 11:00:00 CET')>"
assert str(trigger) == "cron[year='2009', month='2', hour='8-10']"
start_date = timezone.localize(datetime(2009, 1, 1))
correct_next_date = timezone.localize(datetime(2009, 2, 4, 8))
assert trigger.get_next_fire_time(None, start_date) == correct_next_date
示例15: test_cron_extra_coverage
def test_cron_extra_coverage(self, timezone):
# This test has no value other than patching holes in test coverage
trigger = CronTrigger(day='6,8', timezone=timezone)
assert repr(trigger) == "<CronTrigger (day='6,8', timezone='Europe/Berlin')>"
assert str(trigger) == "cron[day='6,8']"
start_date = timezone.localize(datetime(2009, 12, 31))
correct_next_date = timezone.localize(datetime(2010, 1, 6))
assert trigger.get_next_fire_time(None, start_date) == correct_next_date