support for crontab
This commit is contained in:
parent
c48f4a10b1
commit
b8c2649b69
1 changed files with 6 additions and 1 deletions
|
@ -7,6 +7,7 @@ import logging
|
||||||
|
|
||||||
from tornado.ioloop import IOLoop
|
from tornado.ioloop import IOLoop
|
||||||
# from lxml.html.diff import htmldiff
|
# from lxml.html.diff import htmldiff
|
||||||
|
from apscheduler.triggers.cron import CronTrigger
|
||||||
from apscheduler.schedulers.tornado import TornadoScheduler
|
from apscheduler.schedulers.tornado import TornadoScheduler
|
||||||
from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
|
from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
|
||||||
|
|
||||||
|
@ -71,12 +72,16 @@ def scheduler_update(scheduler, id_):
|
||||||
trigger = schedule.get('trigger')
|
trigger = schedule.get('trigger')
|
||||||
if trigger not in ('interval', 'cron'):
|
if trigger not in ('interval', 'cron'):
|
||||||
return
|
return
|
||||||
args = {'trigger': trigger}
|
args = {}
|
||||||
if trigger == 'interval':
|
if trigger == 'interval':
|
||||||
|
args['trigger'] = 'interval'
|
||||||
for unit in 'weeks', 'days', 'hours', 'minutes', 'seconds':
|
for unit in 'weeks', 'days', 'hours', 'minutes', 'seconds':
|
||||||
if 'interval_%s' % unit not in schedule:
|
if 'interval_%s' % unit not in schedule:
|
||||||
continue
|
continue
|
||||||
args[unit] = int(schedule['interval_%s' % unit])
|
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)
|
scheduler.add_job(run_job, id=id_, replace_existing=True, kwargs={'id_': id_}, **args)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue