本文整理匯總了Python中apscheduler.triggers.cron.CronTrigger方法的典型用法代碼示例。如果您正苦於以下問題:Python cron.CronTrigger方法的具體用法?Python cron.CronTrigger怎麽用?Python cron.CronTrigger使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類apscheduler.triggers.cron
的用法示例。
在下文中一共展示了cron.CronTrigger方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __sonarr_full_update_task
# 需要導入模塊: from apscheduler.triggers import cron [as 別名]
# 或者: from apscheduler.triggers.cron import CronTrigger [as 別名]
def __sonarr_full_update_task(self):
if settings.general.getboolean('use_sonarr'):
full_update = settings.sonarr.full_update
if full_update == "Daily":
self.aps_scheduler.add_job(
update_all_episodes, CronTrigger(hour=settings.sonarr.full_update_hour), max_instances=1,
coalesce=True, misfire_grace_time=15, id='update_all_episodes',
name='Update all Episode Subtitles from disk', replace_existing=True)
elif full_update == "Weekly":
self.aps_scheduler.add_job(
update_all_episodes,
CronTrigger(day_of_week=settings.sonarr.full_update_day, hour=settings.sonarr.full_update_hour),
max_instances=1, coalesce=True, misfire_grace_time=15, id='update_all_episodes',
name='Update all Episode Subtitles from disk', replace_existing=True)
elif full_update == "Manually":
self.aps_scheduler.add_job(
update_all_episodes, CronTrigger(year='2100'), max_instances=1, coalesce=True,
misfire_grace_time=15, id='update_all_episodes',
name='Update all Episode Subtitles from disk', replace_existing=True)
示例2: load_events
# 需要導入模塊: from apscheduler.triggers import cron [as 別名]
# 或者: from apscheduler.triggers.cron import CronTrigger [as 別名]
def load_events(self):
"""
For each received synapse that have an event as signal, we add a new job scheduled
to launch the synapse
"""
for synapse in self.list_synapses_with_event:
for signal in synapse.signals:
# We need to loop here again if the synapse has multiple event signals.
# if the signal is an event we add it to the task list.
if signal.name == "event":
my_cron = CronTrigger(year=self.get_parameter_from_dict("year", signal.parameters),
month=self.get_parameter_from_dict("month", signal.parameters),
day=self.get_parameter_from_dict("day", signal.parameters),
week=self.get_parameter_from_dict("week", signal.parameters),
day_of_week=self.get_parameter_from_dict("day_of_week",
signal.parameters),
hour=self.get_parameter_from_dict("hour", signal.parameters),
minute=self.get_parameter_from_dict("minute", signal.parameters),
second=self.get_parameter_from_dict("second", signal.parameters), )
Utils.print_info("Add synapse name \"%s\" to the scheduler: %s" % (synapse.name, my_cron))
self.scheduler.add_job(self.run_synapse_by_name, my_cron, args=[synapse.name])
示例3: __radarr_full_update_task
# 需要導入模塊: from apscheduler.triggers import cron [as 別名]
# 或者: from apscheduler.triggers.cron import CronTrigger [as 別名]
def __radarr_full_update_task(self):
if settings.general.getboolean('use_radarr'):
full_update = settings.radarr.full_update
if full_update == "Daily":
self.aps_scheduler.add_job(
update_all_movies, CronTrigger(hour=settings.radarr.full_update_hour), max_instances=1,
coalesce=True, misfire_grace_time=15,
id='update_all_movies', name='Update all Movie Subtitles from disk', replace_existing=True)
elif full_update == "Weekly":
self.aps_scheduler.add_job(
update_all_movies,
CronTrigger(day_of_week=settings.radarr.full_update_day, hour=settings.radarr.full_update_hour),
max_instances=1, coalesce=True, misfire_grace_time=15, id='update_all_movies',
name='Update all Movie Subtitles from disk', replace_existing=True)
elif full_update == "Manually":
self.aps_scheduler.add_job(
update_all_movies, CronTrigger(year='2100'), max_instances=1, coalesce=True, misfire_grace_time=15,
id='update_all_movies', name='Update all Movie Subtitles from disk', replace_existing=True)
示例4: __update_bazarr_task
# 需要導入模塊: from apscheduler.triggers import cron [as 別名]
# 或者: from apscheduler.triggers.cron import CronTrigger [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)
示例5: schedule
# 需要導入模塊: from apscheduler.triggers import cron [as 別名]
# 或者: from apscheduler.triggers.cron import CronTrigger [as 別名]
def schedule(scheduler, runbook, target, config, dbc, logger):
''' Setup schedule for new runbooks and targets '''
# Default schedule (every minute)
task_schedule = {
'second' : 0,
'minute' : '*',
'hour' : '*',
'day' : '*',
'month' : '*',
'day_of_week' : '*'
}
# If schedule is present override default
if 'schedule' in target['runbooks'][runbook].keys():
if type(target['runbooks'][runbook]['schedule']) == types.DictType:
for key in target['runbooks'][runbook]['schedule'].keys():
task_schedule[key] = target['runbooks'][runbook]['schedule'][key]
elif type(target['runbooks'][runbook]['schedule']) == types.StringType:
breakdown = target['runbooks'][runbook]['schedule'].split(" ")
task_schedule = {
'second' : 0,
'minute' : breakdown[0],
'hour' : breakdown[1],
'day' : breakdown[2],
'month' : breakdown[3],
'day_of_week' : breakdown[4]
}
cron = CronTrigger(
second=task_schedule['second'],
minute=task_schedule['minute'],
hour=task_schedule['hour'],
day=task_schedule['day'],
month=task_schedule['month'],
day_of_week=task_schedule['day_of_week'],
)
return scheduler.add_job(
monitor,
trigger=cron,
args=[runbook, target, config, dbc, logger]
)
示例6: reload
# 需要導入模塊: from apscheduler.triggers import cron [as 別名]
# 或者: from apscheduler.triggers.cron import CronTrigger [as 別名]
def reload(self):
for profile in BackupProfileModel.select():
trigger = None
job_id = f"{profile.id}"
if profile.schedule_mode == "interval":
trigger = cron.CronTrigger(
hour=f"*/{profile.schedule_interval_hours}",
minute=profile.schedule_interval_minutes,
)
elif profile.schedule_mode == "fixed":
trigger = cron.CronTrigger(
hour=profile.schedule_fixed_hour,
minute=profile.schedule_fixed_minute,
)
if self.get_job(job_id) is not None and trigger is not None:
self.reschedule_job(job_id, trigger=trigger)
notifier = RestaticNotifications.pick()()
notifier.deliver(
"Restatic Scheduler", "Background scheduler was changed."
)
logger.debug("Job for profile %s was rescheduled.", profile.name)
elif trigger is not None:
self.add_job(
func=self.create_backup,
args=[profile.id],
trigger=trigger,
id=job_id,
misfire_grace_time=180,
)
logger.debug("New job for profile %s was added.", profile.name)
elif self.get_job(job_id) is not None and trigger is None:
self.remove_job(job_id)
logger.debug("Job for profile %s was removed.", profile.name)
示例7: reload
# 需要導入模塊: from apscheduler.triggers import cron [as 別名]
# 或者: from apscheduler.triggers.cron import CronTrigger [as 別名]
def reload(self):
for profile in BackupProfileModel.select():
trigger = None
job_id = f'{profile.id}'
if profile.schedule_mode == 'interval':
if profile.schedule_interval_hours >= 24:
days = profile.schedule_interval_hours // 24
leftover_hours = profile.schedule_interval_hours % 24
if leftover_hours == 0:
cron_hours = '1'
else:
cron_hours = f'*/{leftover_hours}'
trigger = cron.CronTrigger(day=f'*/{days}',
hour=cron_hours,
minute=profile.schedule_interval_minutes)
else:
trigger = cron.CronTrigger(hour=f'*/{profile.schedule_interval_hours}',
minute=profile.schedule_interval_minutes)
elif profile.schedule_mode == 'fixed':
trigger = cron.CronTrigger(hour=profile.schedule_fixed_hour,
minute=profile.schedule_fixed_minute)
if self.get_job(job_id) is not None and trigger is not None:
self.reschedule_job(job_id, trigger=trigger)
notifier = VortaNotifications.pick()
notifier.deliver(self.tr('Vorta Scheduler'), self.tr('Background scheduler was changed.'))
logger.debug('Job for profile %s was rescheduled.', profile.name)
elif trigger is not None:
self.add_job(
func=self.create_backup,
args=[profile.id],
trigger=trigger,
id=job_id,
misfire_grace_time=180
)
logger.debug('New job for profile %s was added.', profile.name)
elif self.get_job(job_id) is not None and trigger is None:
self.remove_job(job_id)
logger.debug('Job for profile %s was removed.', profile.name)
示例8: parse
# 需要導入模塊: from apscheduler.triggers import cron [as 別名]
# 或者: from apscheduler.triggers.cron import CronTrigger [as 別名]
def parse(cls, expression):
parts = list(reversed(expression.split()))
for i in range(len(parts)):
if parts[i] == '?':
parts[i] = None
return CronTrigger(parts[0], parts[1], parts[2], parts[3], parts[4], parts[5], parts[6], parts[7])
示例9: _add_job_to_scheduler
# 需要導入模塊: from apscheduler.triggers import cron [as 別名]
# 或者: from apscheduler.triggers.cron import CronTrigger [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
示例10: add_new_job
# 需要導入模塊: from apscheduler.triggers import cron [as 別名]
# 或者: from apscheduler.triggers.cron import CronTrigger [as 別名]
def add_new_job(self, job_id, day_of_week_string, hour, minute, url, auto_stop_minutes) -> bool:
print("add a new job with id {}, {}, {}, {}, {}, {}".
format(job_id, day_of_week_string, hour, minute, url, auto_stop_minutes))
my_cron = CronTrigger(hour=hour,
minute=minute,
day_of_week=day_of_week_string)
self.scheduler.add_job(func=self.play_web_radio,
trigger=my_cron,
id=str(job_id),
args=[url, auto_stop_minutes])
return True
示例11: build_trigger
# 需要導入模塊: from apscheduler.triggers import cron [as 別名]
# 或者: from apscheduler.triggers.cron import CronTrigger [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
示例12: jobs
# 需要導入模塊: from apscheduler.triggers import cron [as 別名]
# 或者: from apscheduler.triggers.cron import CronTrigger [as 別名]
def jobs(self):
time = self.setting.get("calender_time", "08:00")
hour, minute = time.split(":")
trigger = CronTrigger(hour=hour, minute=minute)
job = (trigger, self.send_daily_async)
init_trigger = DateTrigger(
datetime.datetime.now() +
datetime.timedelta(seconds=5)
) # 啟動5秒後初始化
init_job = (init_trigger, self.load_timeline_async)
return (job, init_job)
示例13: jobs
# 需要導入模塊: from apscheduler.triggers import cron [as 別名]
# 或者: from apscheduler.triggers.cron import CronTrigger [as 別名]
def jobs(self):
trigger = CronTrigger(hour=5)
def ensure_future_update_all_group_members():
asyncio.ensure_future(self._update_group_list_async())
return ((trigger, ensure_future_update_all_group_members),)
示例14: jobs
# 需要導入模塊: from apscheduler.triggers import cron [as 別名]
# 或者: from apscheduler.triggers.cron import CronTrigger [as 別名]
def jobs(self) -> Iterable[Tuple[CronTrigger, Callable[[], List[Dict[str, Any]]]]]:
if not self.setting.get("auto_update", True):
return tuple()
time = self.setting.get("update-time", "03:30")
hour, minute = time.split(":")
trigger = CronTrigger(hour=hour, minute=minute)
job = (trigger, self.update_auto_async)
return (job,)
示例15: jobs
# 需要導入模塊: from apscheduler.triggers import cron [as 別名]
# 或者: from apscheduler.triggers.cron import CronTrigger [as 別名]
def jobs(self):
trigger = CronTrigger(hour=5)
return ((trigger, self.drop_expired_logins),)