Advertisement
Guest User

Untitled

a guest
Dec 15th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. from taskflow import engines
  2. from taskflow.patterns import graph_flow as gf
  3. from taskflow import task
  4.  
  5.  
  6. class Task(task.Task):
  7.     def __init__(self, name, parents=[]):
  8.         super(Task, self).__init__(name=name)
  9.         self.parents = parents
  10.  
  11.     def execute(self, *args, **kwargs):
  12.         print self.name + ' ' + str(self.parents)
  13.         return True
  14.  
  15.  
  16. def decider(history):
  17.     print history
  18.     return True
  19.  
  20.  
  21. mig1 = Task('mig1')
  22. mig2 = Task('mig2')
  23. mig3 = Task('mig3')
  24. res = Task('res', parents=[mig1.name])
  25. turn_off = Task('turn_off', parents=[res.name, mig2.name])
  26.  
  27. actions = [mig3, mig1, mig2, res, turn_off]
  28.  
  29.  
  30. def get_action(_actions, id):
  31.     for a in _actions:
  32.         if a.name == id:
  33.             return a
  34.  
  35.  
  36. mainflow = gf.Flow('Main')
  37.  
  38. for action in actions:
  39.     mainflow.add(action)
  40.  
  41. for action in actions:
  42.     if action.parents:
  43.         for parent_id in action.parents:
  44.             parent_action = get_action(actions, parent_id)
  45.             mainflow.link(parent_action, action)
  46.  
  47. e = engines.load(mainflow, engine='parallel')
  48. e.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement