Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from taskflow import engines
- from taskflow.patterns import graph_flow as gf
- from taskflow import task
- class Task(task.Task):
- def __init__(self, name, parents=[]):
- super(Task, self).__init__(name=name)
- self.parents = parents
- def execute(self, *args, **kwargs):
- print self.name + ' ' + str(self.parents)
- return True
- def decider(history):
- print history
- return True
- mig1 = Task('mig1')
- mig2 = Task('mig2')
- mig3 = Task('mig3')
- res = Task('res', parents=[mig1.name])
- turn_off = Task('turn_off', parents=[res.name, mig2.name])
- actions = [mig3, mig1, mig2, res, turn_off]
- def get_action(_actions, id):
- for a in _actions:
- if a.name == id:
- return a
- mainflow = gf.Flow('Main')
- for action in actions:
- mainflow.add(action)
- for action in actions:
- if action.parents:
- for parent_id in action.parents:
- parent_action = get_action(actions, parent_id)
- mainflow.link(parent_action, action)
- e = engines.load(mainflow, engine='parallel')
- e.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement