use UTC timezone

This commit is contained in:
Diffido 2018-01-26 15:48:43 +01:00
parent 4261623d1a
commit ddbaa5b0fb

View file

@ -19,6 +19,7 @@ import os
import re import re
import io import io
import json import json
import pytz
import shutil import shutil
import urllib import urllib
import smtplib import smtplib
@ -318,7 +319,10 @@ def get_history(id_, limit=None, add_info=False):
:returns: information about the schedule and its history :returns: information about the schedule and its history
:rtype: dict""" :rtype: dict"""
def _history(id_, limit, queue): def _history(id_, limit, queue):
os.chdir('storage/%s' % id_) try:
os.chdir('storage/%s' % id_)
except:
return queue.put(b'')
cmd = [GIT_CMD, 'log', '--pretty=oneline', '--shortstat'] cmd = [GIT_CMD, 'log', '--pretty=oneline', '--shortstat']
if limit is not None: if limit is not None:
cmd.append('-%s' % limit) cmd.append('-%s' % limit)
@ -356,7 +360,8 @@ def get_last_history(id_):
:returns: information about the schedule and its history :returns: information about the schedule and its history
:rtype: dict""" :rtype: dict"""
history = get_history(id_, limit=1) history = get_history(id_, limit=1)
return history.get('history', [{}])[0] hist = history.get('history') or [{}]
return hist[0]
def get_diff(id_, commit_id='HEAD', old_commit_id=None): def get_diff(id_, commit_id='HEAD', old_commit_id=None):
@ -409,10 +414,16 @@ def scheduler_update(scheduler, id_):
if 'interval_%s' % unit not in schedule: if 'interval_%s' % unit not in schedule:
continue continue
try: try:
args[unit] = int(schedule['interval_%s' % unit]) val = schedule['interval_%s' % unit]
if not val:
continue
args[unit] = int(val)
except Exception: except Exception:
logger.warn('invalid argument on schedule %s: %s parameter %s is not an integer' % logger.warn('invalid argument on schedule %s: %s parameter %s is not an integer' %
(id_, 'interval_%s' % unit, schedule['interval_%s' % unit])) (id_, 'interval_%s' % unit, schedule['interval_%s' % unit]))
if len(args) == 1:
logger.error('no valid interval specified, skipping schedule %s' % id_)
return False
elif trigger == 'cron': elif trigger == 'cron':
try: try:
cron_trigger = CronTrigger.from_crontab(schedule['cron_crontab']) cron_trigger = CronTrigger.from_crontab(schedule['cron_crontab'])
@ -420,6 +431,7 @@ def scheduler_update(scheduler, id_):
except Exception: except Exception:
logger.warn('invalid argument on schedule %s: cron_tab parameter %s is not a valid crontab' % logger.warn('invalid argument on schedule %s: cron_tab parameter %s is not a valid crontab' %
(id_, schedule.get('cron_crontab'))) (id_, schedule.get('cron_crontab')))
return False
git_create_repo(id_) git_create_repo(id_)
try: try:
scheduler.add_job(safe_run_job, id=id_, replace_existing=True, kwargs={'id_': id_}, **args) scheduler.add_job(safe_run_job, id=id_, replace_existing=True, kwargs={'id_': id_}, **args)
@ -664,7 +676,7 @@ def serve():
"""Read configuration and start the server.""" """Read configuration and start the server."""
global EMAIL_FROM, SMTP_SETTINGS global EMAIL_FROM, SMTP_SETTINGS
jobstores = {'default': SQLAlchemyJobStore(url=JOBS_STORE)} jobstores = {'default': SQLAlchemyJobStore(url=JOBS_STORE)}
scheduler = TornadoScheduler(jobstores=jobstores) scheduler = TornadoScheduler(jobstores=jobstores, timezone=pytz.utc)
scheduler.start() scheduler.start()
define('port', default=3210, help='run on the given port', type=int) define('port', default=3210, help='run on the given port', type=int)