From ea342940064182918d6842067ab19f0b38c1ec9e Mon Sep 17 00:00:00 2001 From: evilhero Date: Sat, 25 Nov 2017 20:03:43 -0500 Subject: [PATCH] FIX: Fix for startup errors on clean installs referencing scheduler variables --- mylar/__init__.py | 19 +++++++++++++------ mylar/helpers.py | 13 +++++++++++-- mylar/updater.py | 5 +++-- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/mylar/__init__.py b/mylar/__init__.py index d7bc440b..4cd74af7 100644 --- a/mylar/__init__.py +++ b/mylar/__init__.py @@ -358,7 +358,13 @@ def start(): if _INITIALIZED: #load up the previous runs from the job sql table so we know stuff... - helpers.job_management() + monitors = helpers.job_management() + SCHED_WEEKLY_LAST = monitors['weekly'] + SCHED_SEARCH_LAST = monitors['search'] + SCHED_UPDATER_LAST = monitors['dbupdater'] + SCHED_MONITOR_LAST = monitors['monitor'] + SCHED_VERSION_LAST = monitors['version'] + SCHED_RSS_LAST = monitors['rss'] # Start our scheduled background tasks SCHED.add_job(func=updater.dbUpdate, id='dbupdater', name='DB Updater', args=[None,None,True], trigger=IntervalTrigger(hours=0, minutes=5, timezone='UTC')) @@ -420,19 +426,20 @@ def start(): except: SCHED_WEEKLY_LAST = None + weektimestamp = helpers.utctimestamp() if SCHED_WEEKLY_LAST is not None: weekly_timestamp = float(SCHED_WEEKLY_LAST) else: - weekly_timestamp = helpers.utctimestamp() + weekly_interval + weekly_timestamp = weektimestamp + weekly_interval ws = weeklypullit.Weekly() - duration_diff = (helpers.utctimestamp() - weekly_timestamp)/60 + duration_diff = (weektimestamp - weekly_timestamp)/60 - if duration_diff >= weekly_interval/60: - logger.info('[WEEKLY] Weekly Pull-Update initializing immediately as it has been %s hours since the last run' % (duration_diff/60)) + if abs(duration_diff) >= weekly_interval/60: + logger.info('[WEEKLY] Weekly Pull-Update initializing immediately as it has been %s hours since the last run' % abs(duration_diff/60)) SCHED.add_job(func=ws.run, id='weekly', name='Weekly Pullist', next_run_time=datetime.datetime.utcnow(), trigger=IntervalTrigger(hours=weektimer, minutes=0, timezone='UTC')) else: - weekly_diff = datetime.datetime.utcfromtimestamp(helpers.utctimestamp() + (weekly_interval - (duration_diff * 60))) + weekly_diff = datetime.datetime.utcfromtimestamp(weektimestamp + (weekly_interval - (duration_diff * 60))) logger.fdebug('[WEEKLY] Scheduling next run for @ %s every %s hours' % (weekly_diff, weektimer)) SCHED.add_job(func=ws.run, id='weekly', name='Weekly Pullist', next_run_time=weekly_diff, trigger=IntervalTrigger(hours=weektimer, minutes=0, timezone='UTC')) diff --git a/mylar/helpers.py b/mylar/helpers.py index fc80b861..1138ea2d 100755 --- a/mylar/helpers.py +++ b/mylar/helpers.py @@ -3145,6 +3145,13 @@ def job_management(write=False, job=None, last_run_completed=None, current_run=N monitor_newstatus = ji['status'] monitor_nextrun = ji['next_run_timestamp'] + monitors = {'weekly': mylar.SCHED_WEEKLY_LAST, + 'monitor': mylar.SCHED_MONITOR_LAST, + 'search': mylar.SCHED_SEARCH_LAST, + 'dbupdater': mylar.SCHED_DBUPDATE_LAST, + 'version': mylar.SCHED_VERSION_LAST, + 'rss': mylar.SCHED_RSS_LAST} + #this is for initial startup for jb in mylar.SCHED.get_jobs(): #logger.fdebug('jb: %s' % jb) @@ -3195,8 +3202,10 @@ def job_management(write=False, job=None, last_run_completed=None, current_run=N 'status': newstatus}) if not write: - #logger.info('jobresults: %s' % jobresults) - return jobresults + if len(jobresults) == 0: + return monitors + else: + return jobresults else: if job is None: for x in jobresults: diff --git a/mylar/updater.py b/mylar/updater.py index dd7f333d..9b51f010 100755 --- a/mylar/updater.py +++ b/mylar/updater.py @@ -340,9 +340,10 @@ def dbUpdate(ComicIDList=None, calledfrom=None, sched=False): if sched is False: time.sleep(15) #pause for 15 secs so dont hammer CV and get 500 error else: - helpers.job_management(write=True, job='DB Updater', last_run_completed=helpers.utctimestamp(), status='Waiting') - mylar.UPDATER_STATUS = 'Waiting' break + + helpers.job_management(write=True, job='DB Updater', last_run_completed=helpers.utctimestamp(), status='Waiting') + mylar.UPDATER_STATUS = 'Waiting' logger.info('Update complete') def latest_update(ComicID, LatestIssue, LatestDate):