本文整理汇总了Python中apscheduler.triggers.interval.IntervalTrigger方法的典型用法代码示例。如果您正苦于以下问题:Python interval.IntervalTrigger方法的具体用法?Python interval.IntervalTrigger怎么用?Python interval.IntervalTrigger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apscheduler.triggers.interval
的用法示例。
在下文中一共展示了interval.IntervalTrigger方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_start_de_scheduling_service
# 需要导入模块: from apscheduler.triggers import interval [as 别名]
# 或者: from apscheduler.triggers.interval import IntervalTrigger [as 别名]
def test_start_de_scheduling_service(self, m_start, m_list_available,
m_load, m_list, m_save):
m_list_available.return_value = {
'fake': faker_cluster_state.FakerModelCollector}
fake_collector = faker_cluster_state.FakerModelCollector(
config=mock.Mock(period=777))
m_load.return_value = fake_collector
scheduler = scheduling.DecisionEngineSchedulingService()
scheduler.start()
m_start.assert_called_once_with(scheduler)
jobs = scheduler.get_jobs()
self.assertEqual(2, len(jobs))
job = jobs[0]
self.assertTrue(bool(fake_collector.cluster_data_model))
self.assertIsInstance(job.trigger, interval_trigger.IntervalTrigger)
示例2: test_execute_sync_job_fails
# 需要导入模块: from apscheduler.triggers import interval [as 别名]
# 或者: from apscheduler.triggers.interval import IntervalTrigger [as 别名]
def test_execute_sync_job_fails(self, m_start, m_list_available,
m_load, m_list, m_save):
fake_config = mock.Mock(period=.01)
fake_collector = faker_cluster_state.FakerModelCollector(
config=fake_config)
fake_collector.synchronize = mock.Mock(
side_effect=lambda: eventlet.sleep(.5))
m_list_available.return_value = {
'fake': faker_cluster_state.FakerModelCollector}
m_load.return_value = fake_collector
scheduler = scheduling.DecisionEngineSchedulingService()
scheduler.start()
m_start.assert_called_once_with(scheduler)
jobs = scheduler.get_jobs()
self.assertEqual(2, len(jobs))
job = jobs[0]
job.func()
self.assertFalse(bool(fake_collector.cluster_data_model))
self.assertIsInstance(job.trigger, interval_trigger.IntervalTrigger)
示例3: __update_bazarr_task
# 需要导入模块: from apscheduler.triggers import interval [as 别名]
# 或者: from apscheduler.triggers.interval import IntervalTrigger [as 别名]
def __update_bazarr_task(self):
if PY2:
pass
elif not args.no_update:
task_name = 'Update Bazarr from source on Github'
if args.release_update:
task_name = 'Update Bazarr from release on Github'
if settings.general.getboolean('auto_update'):
self.aps_scheduler.add_job(
check_and_apply_update, IntervalTrigger(hours=6), max_instances=1, coalesce=True,
misfire_grace_time=15, id='update_bazarr', name=task_name, replace_existing=True)
else:
self.aps_scheduler.add_job(
check_and_apply_update, CronTrigger(year='2100'), hour=4, id='update_bazarr', name=task_name,
replace_existing=True)
self.aps_scheduler.add_job(
check_releases, IntervalTrigger(hours=6), max_instances=1, coalesce=True, misfire_grace_time=15,
id='update_release', name='Update Release Info', replace_existing=True)
else:
self.aps_scheduler.add_job(
check_releases, IntervalTrigger(hours=6), max_instances=1, coalesce=True, misfire_grace_time=15,
id='update_release', name='Update Release Info', replace_existing=True)
示例4: schedule_job
# 需要导入模块: from apscheduler.triggers import interval [as 别名]
# 或者: from apscheduler.triggers.interval import IntervalTrigger [as 别名]
def schedule_job(func, name, hours=0, minutes=0, seconds=0, args=None):
"""
Start scheduled job if starting or restarting plexpy.
Reschedule job if Interval Settings have changed.
Remove job if if Interval Settings changed to 0
"""
job = SCHED.get_job(name)
if job:
if hours == 0 and minutes == 0 and seconds == 0:
SCHED.remove_job(name)
logger.info("Removed background task: %s", name)
elif job.trigger.interval != datetime.timedelta(hours=hours, minutes=minutes):
SCHED.reschedule_job(name, trigger=IntervalTrigger(
hours=hours, minutes=minutes, seconds=seconds, timezone=pytz.UTC), args=args)
logger.info("Re-scheduled background task: %s", name)
elif hours > 0 or minutes > 0 or seconds > 0:
SCHED.add_job(func, id=name, trigger=IntervalTrigger(
hours=hours, minutes=minutes, seconds=seconds, timezone=pytz.UTC), args=args)
logger.info("Scheduled background task: %s", name)
示例5: jobs
# 需要导入模块: from apscheduler.triggers import interval [as 别名]
# 或者: from apscheduler.triggers.interval import IntervalTrigger [as 别名]
def jobs(self) -> Iterable[Tuple[IntervalTrigger, Callable[[], Iterable[Dict[str, Any]]]]]:
if not any([self.setting.get(s, True) for s in self.rss.keys()]):
return tuple()
sub_groups = self.setting.get("notify_groups", [])
sub_users = self.setting.get("notify_privates", [])
if not (sub_groups or sub_users):
return tuple()
if self.news_interval_auto:
# 如果设置为自动
self.auto_job()
return tuple()
interval = self.setting.get("news_interval_minutes", 30)
trigger = IntervalTrigger(
minutes=interval, start_date=datetime.datetime.now()+datetime.timedelta(seconds=60))
job = (trigger, self.send_news_async)
return (job,)
示例6: auto_job
# 需要导入模块: from apscheduler.triggers import interval [as 别名]
# 或者: from apscheduler.triggers.interval import IntervalTrigger [as 别名]
def auto_job(self):
after_60s = datetime.datetime.now()+datetime.timedelta(seconds=60)
# spider 为20分钟间隔
self.scheduler.add_job(
self.send_spider_news_async,
trigger=IntervalTrigger(minutes=20, start_date=after_60s),
misfire_grace_time=60,
coalesce=True,
max_instances=1,
)
# 每个 rss 启动第一个任务
subscribes = [s for s in self.rss.keys() if self.setting.get(s, True)]
for source in subscribes:
self.scheduler.add_job(
self.send_rss_news_async,
args=(source,),
id=source,
trigger=DateTrigger(after_60s),
misfire_grace_time=60,
coalesce=True,
max_instances=1,
)
示例7: _add_job_to_scheduler
# 需要导入模块: from apscheduler.triggers import interval [as 别名]
# 或者: from apscheduler.triggers.interval import IntervalTrigger [as 别名]
def _add_job_to_scheduler(self, trigger):
trigger_type_ref = trigger['type']
trigger_type = TIMER_TRIGGER_TYPES[trigger_type_ref]
try:
util_schema.validate(instance=trigger['parameters'],
schema=trigger_type['parameters_schema'],
cls=util_schema.CustomValidator,
use_default=True,
allow_default_none=True)
except jsonschema.ValidationError as e:
LOG.error('Exception scheduling timer: %s, %s',
trigger['parameters'], e, exc_info=True)
raise # Or should we just return?
time_spec = trigger['parameters']
time_zone = aps_utils.astimezone(trigger['parameters'].get('timezone'))
time_type = None
if trigger_type['name'] == 'st2.IntervalTimer':
unit = time_spec.get('unit', None)
value = time_spec.get('delta', None)
time_type = IntervalTrigger(**{unit: value, 'timezone': time_zone})
elif trigger_type['name'] == 'st2.DateTimer':
# Raises an exception if date string isn't a valid one.
dat = date_parser.parse(time_spec.get('date', None))
time_type = DateTrigger(dat, timezone=time_zone)
elif trigger_type['name'] == 'st2.CronTimer':
cron = time_spec.copy()
cron['timezone'] = time_zone
time_type = CronTrigger(**cron)
utc_now = date_utils.get_datetime_utc_now()
if hasattr(time_type, 'run_date') and utc_now > time_type.run_date:
LOG.warning('Not scheduling expired timer: %s : %s',
trigger['parameters'], time_type.run_date)
else:
self._add_job(trigger, time_type)
return time_type
示例8: _normalize_coerce_interval
# 需要导入模块: from apscheduler.triggers import interval [as 别名]
# 或者: from apscheduler.triggers.interval import IntervalTrigger [as 别名]
def _normalize_coerce_interval(
self, value: str
) -> Tuple[Type, Optional[Tuple[int, int, int, int, int]]]:
args = NAME_INTERVAL_MAP.get(value)
if args is None:
if any(x.isalpha() for x in value):
parsed_value = parse_time_from_string_with_units(value)
if parsed_value:
args = seconds_as_interval_tuple(parsed_value)
else:
for c in '.:/':
value = value.replace(c, ' ')
filled_args = self._fill_args(value, 5, '0')
args = tuple(int(x) for x in filled_args) # type: ignore
return IntervalTrigger, args
示例9: test_job_execution
# 需要导入模块: from apscheduler.triggers import interval [as 别名]
# 或者: from apscheduler.triggers.interval import IntervalTrigger [as 别名]
def test_job_execution(capsys, cfg, mocker):
container = mocker.MagicMock(Container)
container.name = 'foo_0'
container.exec_run.return_value = (0, b'')
cfg.client.containers.get.return_value = container
def docker_containers(filters=None):
if filters['status'] == 'paused':
return []
if filters['status'] == 'running':
return [container]
start_scheduler()
cfg.client.containers.list = docker_containers
definitions = {
'foo': {
'command': 'sleep 2',
'environment': {},
'max': 2,
'timezone': 'UTC',
'trigger': (IntervalTrigger, (0, 0, 0, 0, 1)),
'jitter': None,
'user': 'test',
}
}
add('void', definitions)
sleep(2.5)
scheduler.shutdown(wait=False)
container.exec_run.assert_has_calls(
2 * [mocker.call(cmd='sleep 2', user='test', environment={}, workdir=None)]
)
示例10: __sonarr_update_task
# 需要导入模块: from apscheduler.triggers import interval [as 别名]
# 或者: from apscheduler.triggers.interval import IntervalTrigger [as 别名]
def __sonarr_update_task(self):
if settings.general.getboolean('use_sonarr'):
self.aps_scheduler.add_job(
update_series, IntervalTrigger(minutes=1), max_instances=1, coalesce=True, misfire_grace_time=15,
id='update_series', name='Update Series list from Sonarr')
self.aps_scheduler.add_job(
sync_episodes, IntervalTrigger(minutes=5), max_instances=1, coalesce=True, misfire_grace_time=15,
id='sync_episodes', name='Sync episodes with Sonarr')
示例11: __radarr_update_task
# 需要导入模块: from apscheduler.triggers import interval [as 别名]
# 或者: from apscheduler.triggers.interval import IntervalTrigger [as 别名]
def __radarr_update_task(self):
if settings.general.getboolean('use_radarr'):
self.aps_scheduler.add_job(
update_movies, IntervalTrigger(minutes=5), max_instances=1, coalesce=True, misfire_grace_time=15,
id='update_movies', name='Update Movie list from Radarr')
示例12: __cache_cleanup_task
# 需要导入模块: from apscheduler.triggers import interval [as 别名]
# 或者: from apscheduler.triggers.interval import IntervalTrigger [as 别名]
def __cache_cleanup_task(self):
self.aps_scheduler.add_job(cache_maintenance, IntervalTrigger(hours=24), max_instances=1, coalesce=True,
misfire_grace_time=15, id='cache_cleanup', name='Cache maintenance')
示例13: __upgrade_subtitles_task
# 需要导入模块: from apscheduler.triggers import interval [as 别名]
# 或者: from apscheduler.triggers.interval import IntervalTrigger [as 别名]
def __upgrade_subtitles_task(self):
if settings.general.getboolean('upgrade_subs') and \
(settings.general.getboolean('use_sonarr') or settings.general.getboolean('use_radarr')):
self.aps_scheduler.add_job(
upgrade_subtitles, IntervalTrigger(hours=int(settings.general.upgrade_frequency)), max_instances=1,
coalesce=True, misfire_grace_time=15, id='upgrade_subtitles',
name='Upgrade previously downloaded Subtitles', replace_existing=True)
示例14: build_trigger
# 需要导入模块: from apscheduler.triggers import interval [as 别名]
# 或者: from apscheduler.triggers.interval import IntervalTrigger [as 别名]
def build_trigger(self, type, value):
"""
build a trigger for a schuduled job
:param type: cron, interval, delta, date
:param value: value to convert for a scheduled job
:return: appropriate trigger
"""
trigger = None
if type == "cron":
split_cron = value.split(" ")
trigger = CronTrigger(minute=split_cron[0],
hour=split_cron[1],
day=split_cron[2],
month=split_cron[3],
day_of_week=split_cron[4])
elif type == "interval":
seconds = self.get_interval(value)
trigger = IntervalTrigger(seconds=seconds)
elif type == "date":
trigger = DateTrigger(run_date=value, timezone=self.timezone)
elif type == "delta":
dt = self.get_interval(value, date=True)
trigger = DateTrigger(run_date=dt, timezone=self.timezone)
else:
raise ValueError("Unrecognized type %s", type)
return trigger
示例15: main
# 需要导入模块: from apscheduler.triggers import interval [as 别名]
# 或者: from apscheduler.triggers.interval import IntervalTrigger [as 别名]
def main():
args = parse_args()
if args.debug:
logger.setLevel(logging.DEBUG)
scheme = 'https' if args.secure else 'http'
status_url = '{}://{}:{}{}'.format(scheme, args.ip, args.port,
args.status_path)
health_url = '{}://{}:{}{}'.format(scheme, args.ip, args.port,
args.health_path)
eureka = EurekaClient(args.name, args.port, args.ip,
eureka_url=args.eureka,
instance_id=args.instance_id,
status_page_url=status_url,
health_check_url=health_url)
loop = asyncio.get_event_loop()
loop.run_until_complete(eureka.register())
logger.info('Registered with eureka as %s', eureka.instance_id)
scheduler = AsyncIOScheduler({'event_loop': loop})
@scheduler.scheduled_job(IntervalTrigger(seconds=args.interval))
async def renew_lease():
try:
logger.debug('Attempting to renew the lease...')
await eureka.renew()
logger.info('Lease renewed')
except EurekaException as e:
if e.status == HTTPStatus.NOT_FOUND:
logger.info('Lease expired, re-registering.')
await eureka.register()
return
logger.error('Error performing renewal: %s', e)
scheduler.start()
try:
logger.info('Running')
with contextlib.suppress(KeyboardInterrupt):
loop.run_forever()
finally:
scheduler.shutdown()
loop.run_until_complete(eureka.deregister())
loop.close()