Merge pull request #1398 from niphlod/fix/redis_scheduler
feature parity (cron recurrence) with scheduler
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
Scheduler with redis backend
|
Scheduler with redis backend
|
||||||
---------------------------------
|
---------------------------------
|
||||||
"""
|
"""
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
@@ -475,7 +476,10 @@ class RScheduler(Scheduler):
|
|||||||
logger.info('nothing to do')
|
logger.info('nothing to do')
|
||||||
return None
|
return None
|
||||||
times_run = task.times_run + 1
|
times_run = task.times_run + 1
|
||||||
if not task.prevent_drift:
|
if task.cronline:
|
||||||
|
cron_recur = CronParser(task.cronline, now.replace(second=0))
|
||||||
|
next_run_time = cron_recur.get_next()
|
||||||
|
elif not task.prevent_drift:
|
||||||
next_run_time = task.last_run_time + datetime.timedelta(
|
next_run_time = task.last_run_time + datetime.timedelta(
|
||||||
seconds=task.period
|
seconds=task.period
|
||||||
)
|
)
|
||||||
@@ -711,13 +715,20 @@ class RScheduler(Scheduler):
|
|||||||
tuuid = 'uuid' in kwargs and kwargs.pop('uuid') or web2py_uuid()
|
tuuid = 'uuid' in kwargs and kwargs.pop('uuid') or web2py_uuid()
|
||||||
tname = 'task_name' in kwargs and kwargs.pop('task_name') or function
|
tname = 'task_name' in kwargs and kwargs.pop('task_name') or function
|
||||||
immediate = 'immediate' in kwargs and kwargs.pop('immediate') or None
|
immediate = 'immediate' in kwargs and kwargs.pop('immediate') or None
|
||||||
rtn = self.db.scheduler_task.validate_and_insert(
|
cronline = kwargs.get('cronline')
|
||||||
function_name=function,
|
kwargs.update(function_name=function,
|
||||||
task_name=tname,
|
task_name=tname,
|
||||||
args=targs,
|
args=targs,
|
||||||
vars=tvars,
|
vars=tvars,
|
||||||
uuid=tuuid,
|
uuid=tuuid)
|
||||||
**kwargs)
|
if cronline:
|
||||||
|
try:
|
||||||
|
start_time = kwargs.get('start_time', self.now)
|
||||||
|
next_run_time = CronParser(cronline, start_time).get_next()
|
||||||
|
kwargs.update(start_time=start_time, next_run_time=next_run_time)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
rtn = self.db.scheduler_task.validate_and_insert(**kwargs)
|
||||||
if not rtn.errors:
|
if not rtn.errors:
|
||||||
rtn.uuid = tuuid
|
rtn.uuid = tuuid
|
||||||
if immediate:
|
if immediate:
|
||||||
|
|||||||
Reference in New Issue
Block a user