fixes #1191
fix is in lines 828-835 . needed to backport total_seconds for py2.6 (694-701). everything else is just pep8.
This commit is contained in:
+20
-9
@@ -314,7 +314,7 @@ def executor(queue, task, out):
|
|||||||
vars = loads(task.vars, object_hook=_decode_dict)
|
vars = loads(task.vars, object_hook=_decode_dict)
|
||||||
result = dumps(_function(*args, **vars))
|
result = dumps(_function(*args, **vars))
|
||||||
else:
|
else:
|
||||||
### for testing purpose only
|
# for testing purpose only
|
||||||
result = eval(task.function)(
|
result = eval(task.function)(
|
||||||
*loads(task.args, object_hook=_decode_dict),
|
*loads(task.args, object_hook=_decode_dict),
|
||||||
**loads(task.vars, object_hook=_decode_dict))
|
**loads(task.vars, object_hook=_decode_dict))
|
||||||
@@ -681,8 +681,7 @@ class Scheduler(MetaScheduler):
|
|||||||
'scheduler_task_deps',
|
'scheduler_task_deps',
|
||||||
Field('job_name', default='job_0'),
|
Field('job_name', default='job_0'),
|
||||||
Field('task_parent', 'integer',
|
Field('task_parent', 'integer',
|
||||||
requires=IS_IN_DB(db, 'scheduler_task.id',
|
requires=IS_IN_DB(db, 'scheduler_task.id', '%(task_name)s')
|
||||||
'%(task_name)s')
|
|
||||||
),
|
),
|
||||||
Field('task_child', 'reference scheduler_task'),
|
Field('task_child', 'reference scheduler_task'),
|
||||||
Field('can_visit', 'boolean', default=False),
|
Field('can_visit', 'boolean', default=False),
|
||||||
@@ -692,6 +691,14 @@ class Scheduler(MetaScheduler):
|
|||||||
if migrate is not False:
|
if migrate is not False:
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def total_seconds(td):
|
||||||
|
# backport for py2.6
|
||||||
|
if hasattr(td, 'total_seconds'):
|
||||||
|
return td.total_seconds()
|
||||||
|
else:
|
||||||
|
return (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10 ** 6) / 10.0 ** 6
|
||||||
|
|
||||||
def loop(self, worker_name=None):
|
def loop(self, worker_name=None):
|
||||||
"""Main loop
|
"""Main loop
|
||||||
|
|
||||||
@@ -733,7 +740,8 @@ class Scheduler(MetaScheduler):
|
|||||||
logger.debug('sleeping...')
|
logger.debug('sleeping...')
|
||||||
if self.max_empty_runs != 0:
|
if self.max_empty_runs != 0:
|
||||||
logger.debug('empty runs %s/%s',
|
logger.debug('empty runs %s/%s',
|
||||||
self.w_stats.empty_runs, self.max_empty_runs)
|
self.w_stats.empty_runs,
|
||||||
|
self.max_empty_runs)
|
||||||
if self.w_stats.empty_runs >= self.max_empty_runs:
|
if self.w_stats.empty_runs >= self.max_empty_runs:
|
||||||
logger.info(
|
logger.info(
|
||||||
'empty runs limit reached, killing myself')
|
'empty runs limit reached, killing myself')
|
||||||
@@ -819,9 +827,13 @@ class Scheduler(MetaScheduler):
|
|||||||
seconds=task.period
|
seconds=task.period
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
next_run_time = task.start_time + datetime.timedelta(
|
# calc next_run_time based on available slots
|
||||||
seconds=task.period * times_run
|
# see #1191
|
||||||
)
|
next_run_time = task.start_time
|
||||||
|
secondspassed = self.total_seconds(now - next_run_time)
|
||||||
|
steps = secondspassed // task.period + 1
|
||||||
|
next_run_time += datetime.timedelta(seconds=task.period * steps)
|
||||||
|
|
||||||
if times_run < task.repeats or task.repeats == 0:
|
if times_run < task.repeats or task.repeats == 0:
|
||||||
# need to run (repeating task)
|
# need to run (repeating task)
|
||||||
run_again = True
|
run_again = True
|
||||||
@@ -926,7 +938,7 @@ class Scheduler(MetaScheduler):
|
|||||||
and QUEUED or task.retry_failed == -1
|
and QUEUED or task.retry_failed == -1
|
||||||
and QUEUED or st_mapping)
|
and QUEUED or st_mapping)
|
||||||
db(st.id == task.task_id).update(
|
db(st.id == task.task_id).update(
|
||||||
times_failed=db.scheduler_task.times_failed + 1,
|
times_failed=st.times_failed + 1,
|
||||||
next_run_time=task.next_run_time,
|
next_run_time=task.next_run_time,
|
||||||
status=status
|
status=status
|
||||||
)
|
)
|
||||||
@@ -1133,7 +1145,6 @@ class Scheduler(MetaScheduler):
|
|||||||
(st.id.belongs(no_deps))
|
(st.id.belongs(no_deps))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
limit = len(all_workers) * (50 / (len(wkgroups) or 1))
|
limit = len(all_workers) * (50 / (len(wkgroups) or 1))
|
||||||
# if there are a moltitude of tasks, let's figure out a maximum of
|
# if there are a moltitude of tasks, let's figure out a maximum of
|
||||||
# tasks per worker. This can be further tuned with some added
|
# tasks per worker. This can be further tuned with some added
|
||||||
|
|||||||
Reference in New Issue
Block a user