本文整理汇总了Python中apscheduler.triggers.cron.CronTrigger.get_next_fire_time方法的典型用法代码示例。如果您正苦于以下问题:Python CronTrigger.get_next_fire_time方法的具体用法?Python CronTrigger.get_next_fire_time怎么用?Python CronTrigger.get_next_fire_time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apscheduler.triggers.cron.CronTrigger
的用法示例。
在下文中一共展示了CronTrigger.get_next_fire_time方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_end_date
# 需要导入模块: from apscheduler.triggers.cron import CronTrigger [as 别名]
# 或者: from apscheduler.triggers.cron.CronTrigger import get_next_fire_time [as 别名]
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
示例2: test_cron_weekday_nomatch
# 需要导入模块: from apscheduler.triggers.cron import CronTrigger [as 别名]
# 或者: from apscheduler.triggers.cron.CronTrigger import get_next_fire_time [as 别名]
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
示例3: test_cron_trigger_3
# 需要导入模块: from apscheduler.triggers.cron import CronTrigger [as 别名]
# 或者: from apscheduler.triggers.cron.CronTrigger import get_next_fire_time [as 别名]
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
示例4: test_cron_trigger_4
# 需要导入模块: from apscheduler.triggers.cron import CronTrigger [as 别名]
# 或者: from apscheduler.triggers.cron.CronTrigger import get_next_fire_time [as 别名]
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
示例5: test_cron_trigger_1
# 需要导入模块: from apscheduler.triggers.cron import CronTrigger [as 别名]
# 或者: from apscheduler.triggers.cron.CronTrigger import get_next_fire_time [as 别名]
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
示例6: test_week_2
# 需要导入模块: from apscheduler.triggers.cron import CronTrigger [as 别名]
# 或者: from apscheduler.triggers.cron.CronTrigger import get_next_fire_time [as 别名]
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
示例7: test_week_1
# 需要导入模块: from apscheduler.triggers.cron import CronTrigger [as 别名]
# 或者: from apscheduler.triggers.cron.CronTrigger import get_next_fire_time [as 别名]
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
示例8: test_cron_year_list
# 需要导入模块: from apscheduler.triggers.cron import CronTrigger [as 别名]
# 或者: from apscheduler.triggers.cron.CronTrigger import get_next_fire_time [as 别名]
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
示例9: add_random_tasks
# 需要导入模块: from apscheduler.triggers.cron import CronTrigger [as 别名]
# 或者: from apscheduler.triggers.cron.CronTrigger import get_next_fire_time [as 别名]
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)
示例10: test_previous_fire_time_1
# 需要导入模块: from apscheduler.triggers.cron import CronTrigger [as 别名]
# 或者: from apscheduler.triggers.cron.CronTrigger import get_next_fire_time [as 别名]
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
示例11: test_cron_weekday_positional
# 需要导入模块: from apscheduler.triggers.cron import CronTrigger [as 别名]
# 或者: from apscheduler.triggers.cron.CronTrigger import get_next_fire_time [as 别名]
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
示例12: test_dst_change
# 需要导入模块: from apscheduler.triggers.cron import CronTrigger [as 别名]
# 或者: from apscheduler.triggers.cron.CronTrigger import get_next_fire_time [as 别名]
def test_dst_change(self):
"""
Making sure that CronTrigger works correctly when crossing the DST switch threshold.
Note that you should explicitly compare datetimes as strings to avoid the internal datetime comparison which
would test for equality in the UTC timezone.
"""
eastern = pytz.timezone("US/Eastern")
trigger = CronTrigger(minute="*/30", timezone=eastern)
datetime_edt = eastern.localize(datetime(2013, 11, 3, 1, 5), is_dst=True)
correct_next_date = eastern.localize(datetime(2013, 11, 3, 1, 30), is_dst=True)
assert str(trigger.get_next_fire_time(None, datetime_edt)) == str(correct_next_date)
datetime_edt = eastern.localize(datetime(2013, 11, 3, 1, 35), is_dst=True)
correct_next_date = eastern.localize(datetime(2013, 11, 3, 1), is_dst=False)
assert str(trigger.get_next_fire_time(None, datetime_edt)) == str(correct_next_date)
示例13: test_different_tz
# 需要导入模块: from apscheduler.triggers.cron import CronTrigger [as 别名]
# 或者: from apscheduler.triggers.cron.CronTrigger import get_next_fire_time [as 别名]
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
示例14: test_cron_weekday_overlap
# 需要导入模块: from apscheduler.triggers.cron import CronTrigger [as 别名]
# 或者: from apscheduler.triggers.cron.CronTrigger import get_next_fire_time [as 别名]
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
示例15: test_cron_extra_coverage
# 需要导入模块: from apscheduler.triggers.cron import CronTrigger [as 别名]
# 或者: from apscheduler.triggers.cron.CronTrigger import get_next_fire_time [as 别名]
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