scheduler: Simplify DependencyTaskGroup interface

Instead of passing a function that takes one argument and returns a task
that takes no arguments, simply pass a task that takes one argument.

Change-Id: I73d5f137d5db492c09e6887f80e7e759734c211f
This commit is contained in:
Zane Bitter 2013-06-13 20:03:27 +02:00
parent 26812e34bd
commit f22691904f
3 changed files with 12 additions and 19 deletions

View File

@ -294,7 +294,7 @@ class Stack(object):
res = None
def resource_create(r):
return r.create
return r.create()
create_task = scheduler.DependencyTaskGroup(self.dependencies,
resource_create)

View File

@ -263,19 +263,22 @@ class DependencyTaskGroup(object):
A task which manages a group of subtasks that have ordering dependencies.
"""
def __init__(self, dependencies, make_task=lambda o: o,
def __init__(self, dependencies, task=lambda o: o(),
reverse=False, name=None):
"""
Initialise with the task dependencies and (optionally) a function for
creating a task from each dependency object.
Initialise with the task dependencies and (optionally) a task to run on
each.
If no task is supplied, it is assumed that the tasks are stored
directly in the dependency tree. If a task is supplied, the object
stored in the dependency tree is passed as an argument.
"""
self._runners = dict((o, TaskRunner(make_task(o)))
for o in dependencies)
self._runners = dict((o, TaskRunner(task, o)) for o in dependencies)
self._graph = dependencies.graph(reverse=reverse)
if name is None:
name = '(%s) %s' % (getattr(make_task, '__name__',
task_description(make_task)),
name = '(%s) %s' % (getattr(task, '__name__',
task_description(task)),
str(dependencies))
self.name = name

View File

@ -166,19 +166,9 @@ class DependencyTaskGroupTest(mox.MoxTestBase):
def _dep_test(self, *edges):
dummy = DummyTask(getattr(self, 'steps', 3))
class TaskMaker(object):
def __init__(self, name):
self.name = name
def __repr__(self):
return 'Dummy task "%s"' % self.name
def __call__(self, *args, **kwargs):
return dummy(self.name, *args, **kwargs)
deps = dependencies.Dependencies(edges)
tg = scheduler.DependencyTaskGroup(deps, TaskMaker)
tg = scheduler.DependencyTaskGroup(deps, dummy)
self.mox.StubOutWithMock(dummy, 'do_step')