summaryrefslogtreecommitdiff
path: root/taskflow/patterns
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@gmail.com>2013-07-06 12:27:35 -0700
committerJoshua Harlow <harlowja@gmail.com>2013-07-06 12:34:48 -0700
commit1f7edf2316fbd9cfccc26e0fb2f396c719bfba9f (patch)
tree7f6814c0131a1b31f6e4158882637b192fc97732 /taskflow/patterns
parentd746a93171ccfb5507f8a71b3e71814fc89d2a7f (diff)
downloadtaskflow-1f7edf2316fbd9cfccc26e0fb2f396c719bfba9f.tar.gz
Clear out before connecting.
Since the node set may have been altered since the last connect we want to make sure clear out the edges and the providers of items before connecting. Change-Id: I73e6b3bc5d83a82d2b13dbb6b06c66e794d66e9c
Diffstat (limited to 'taskflow/patterns')
-rw-r--r--taskflow/patterns/graph_flow.py39
1 files changed, 23 insertions, 16 deletions
diff --git a/taskflow/patterns/graph_flow.py b/taskflow/patterns/graph_flow.py
index 83a7433..d0b7f99 100644
--- a/taskflow/patterns/graph_flow.py
+++ b/taskflow/patterns/graph_flow.py
@@ -95,29 +95,36 @@ class Flow(linear_flow.Flow):
if self._runners:
return self._runners
+ # Clear out all edges (since we want to do a fresh connection)
+ for (u, v) in self._graph.edges():
+ self._graph.remove_edge(u, v)
+
# Link providers to requirers.
#
# TODO(harlowja): allow for developers to manually establish these
# connections instead of automatically doing it for them??
for n in self._graph.nodes_iter():
+ n_providers = {}
n_requires = set(utils.get_attr(n.task, 'requires', []))
- LOG.debug("Finding providers of %s for %s", n_requires, n)
- for p in self._graph.nodes_iter():
- if not n_requires:
- break
- if n is p:
- continue
- p_provides = set(utils.get_attr(p.task, 'provides', []))
- p_satisfies = n_requires & p_provides
- if p_satisfies:
- # P produces for N so thats why we link P->N and not N->P
- self._add_dependency(p, n)
- for k in p_satisfies:
- n.providers[k] = p
- LOG.debug("Found provider of %s from %s", p_satisfies, p)
- n_requires = n_requires - p_satisfies
if n_requires:
- raise exc.MissingDependencies(n, sorted(n_requires))
+ LOG.debug("Finding providers of %s for %s", n_requires, n)
+ for p in self._graph.nodes_iter():
+ if n is p:
+ continue
+ p_provides = set(utils.get_attr(p.task, 'provides', []))
+ p_satisfies = n_requires & p_provides
+ if p_satisfies:
+ # P produces for N so thats why we link P->N
+ # and not N->P
+ self._add_dependency(p, n)
+ for k in p_satisfies:
+ n_providers[k] = p
+ LOG.debug("Found provider of %s from %s",
+ p_satisfies, p)
+ n_requires = n_requires - p_satisfies
+ if n_requires:
+ raise exc.MissingDependencies(n, sorted(n_requires))
+ n.providers = n_providers
# Now figure out the order so that we can give the runners there
# optional item providers as well as figure out the topological run