From b8c2649b694d7145bee58c449edcaa30b5abf5c7 Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Sat, 20 Jan 2018 18:10:31 +0100 Subject: [PATCH] support for crontab --- diffido.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/diffido.py b/diffido.py index 73e2e26..ab3180d 100755 --- a/diffido.py +++ b/diffido.py @@ -7,6 +7,7 @@ import logging from tornado.ioloop import IOLoop # from lxml.html.diff import htmldiff +from apscheduler.triggers.cron import CronTrigger from apscheduler.schedulers.tornado import TornadoScheduler from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore @@ -71,12 +72,16 @@ def scheduler_update(scheduler, id_): trigger = schedule.get('trigger') if trigger not in ('interval', 'cron'): return - args = {'trigger': trigger} + args = {} if trigger == 'interval': + args['trigger'] = 'interval' for unit in 'weeks', 'days', 'hours', 'minutes', 'seconds': if 'interval_%s' % unit not in schedule: continue args[unit] = int(schedule['interval_%s' % unit]) + elif trigger == 'cron': + cron_trigger = CronTrigger.from_crontab(schedule.get('cron_crontab')) + args['trigger'] = cron_trigger scheduler.add_job(run_job, id=id_, replace_existing=True, kwargs={'id_': id_}, **args)