Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_jitter_produces_different_valid_results(self, timezone):
trigger = IntervalTrigger(seconds=5, timezone=timezone, jitter=3)
now = datetime.now(timezone)
results = set()
for _ in range(0, 100):
next_fire_time = trigger.get_next_fire_time(None, now)
results.add(next_fire_time)
assert timedelta(seconds=2) <= (next_fire_time - now) <= timedelta(seconds=8)
assert 1 < len(results)
on_init = self._find_filament_func('on_init')
if on_init and self._zero_args(on_init):
self._filament_module.on_init()
if self._find_filament_func('on_interval'):
self.scheduler.add_executor(ThreadPoolExecutor(max_workers=4))
self.scheduler.start()
def on_interval():
try:
self._filament_module.on_interval()
except Exception:
self._logger.error('Unexpected error on interval elapsed %s'
% traceback.format_exc())
self.scheduler.add_job(on_interval,
IntervalTrigger(),
seconds=self._interval,
max_instances=4,
misfire_grace_time=60)
if len(self._cols) > 0:
try:
self._ansi_term.setup_console()
except TermInitializationError:
panic('fibratus run: ERROR - console initialization failed')
def playlist_info_update_task():
nonlocal channels, livestream, playlist_update_counter, influx_client
for channel in channels:
if livestream['active'] and channel == livestream['CHANNEL']:
playlist_update_counter = (playlist_update_counter + 1) % 5
if playlist_update_counter == 1:
update_livestream_info(channels, livestream)
else:
continue
else:
update_mpd_info(channel, channels[channel], influx_client)
bg_scheduler.add_job(func=playlist_info_update_task,
trigger=IntervalTrigger(seconds=1),
id='playlist_update',
name='Update [channel].json\'s',
replace_existing=True)
# Shut down cleanly
atexit.register(lambda: bg_scheduler.shutdown())
atexit.register(lambda: db.save_pickle(livestream))
# Return the state which will be mutated by the bg_scheduler
return channels, livestream
def schedule_update_job():
if not args.no_update:
if settings.general.getboolean('auto_update'):
scheduler.add_job(check_and_apply_update, IntervalTrigger(hours=6), max_instances=1, coalesce=True,
misfire_grace_time=15, id='update_bazarr',
name='Update Bazarr from source on Github' if not args.release_update else 'Update Bazarr from release on Github',
replace_existing=True)
else:
scheduler.add_job(check_and_apply_update, CronTrigger(year='2100'), hour=4, id='update_bazarr',
name='Update Bazarr from source on Github' if not args.release_update else 'Update Bazarr from release on Github',
replace_existing=True)
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:
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)
def schedule_upgrade_subs():
if settings.general.getboolean('upgrade_subs') and (settings.general.getboolean('use_sonarr') or
settings.general.getboolean('use_radarr')):
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)
# operator, so we compare the stringified version. Gah.
elif str(job.trigger) != str(trig):
print("Removing trigger:", str(job.trigger), str(trig))
self.scheduler_manager.remove_job(job_id)
start_date = datetime.datetime.now()
current_jobs = self.scheduler_manager.get_jobs()
for job_name, params in activeScheduledTasks.target_jobs.items():
if job_name not in active_jobs:
assert params['name'].startswith("AUTO: ")
print("Adding job: %s" % job_name)
if params.get('interval'):
trig = apscheduler.triggers.interval.IntervalTrigger(
seconds = params.get('interval'),
start_date = start_date,
)
start_date = start_date + datetime.timedelta(minutes=5)
else:
trig = apscheduler.triggers.cron.CronTrigger(
month = params.get('month', None),
day = params.get('day', None),
day_of_week = params.get('day_of_week', None),
hour = params.get('hour', None),
minute = params.get('minute', None),
)
self.scheduler_manager.add_trigger_job(
job_class_string = job_name,
name = params['name'],
name='Update Bazarr from source on Github' if not args.release_update else 'Update Bazarr from release on Github',
replace_existing=True)
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:
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)
if settings.general.getboolean('use_sonarr'):
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')
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')
if settings.general.getboolean('use_radarr'):
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')
def schedule_wanted_search():
if settings.general.getboolean('use_sonarr') or settings.general.getboolean('use_radarr'):
scheduler.add_job(wanted_search_missing_subtitles,
IntervalTrigger(hours=int(settings.general.wanted_search_frequency)), max_instances=1,
coalesce=True, misfire_grace_time=15, id='wanted_search_missing_subtitles',
name='Search for wanted Subtitles', replace_existing=True)
def schedule_upgrade_subs():
if settings.general.getboolean('upgrade_subs') and (settings.general.getboolean('use_sonarr') or
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(u"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(u"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(u"Scheduled background task: %s", name)
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:
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))
logger.info("Re-scheduled background task: %s", name)
elif hours > 0 or minutes > 0:
SCHED.add_job(function, id=name, trigger=IntervalTrigger(
hours=hours, minutes=minutes))
logger.info("Scheduled background task: %s", name)
def __init__(self):
self.history = History()
self.instance_list = {}
self.token_list = {}
self.scheduler = BackgroundScheduler()
self.scheduler.start()
self.scheduler.add_job(
func=self._remove_staleinstances,
trigger=IntervalTrigger(seconds=60),
id='stale_instance_remover',
name='Remove stale instances if no heartbeat in 60 seconds',
replace_existing=True
)
self.scheduler.add_job(
func=self._update_history_count,
trigger=IntervalTrigger(seconds=30),
id='update history',
name='update client and instance count every 30 seconds',
replace_existing=True
)