Jump to: navigation, search

Difference between revisions of "TaskFlow/Patterns and Engines Documentation"

Line 31: Line 31:
 
Example:<br />
 
Example:<br />
 
     flow = (ParallelFlow().add(blocks.Task(Adder("add"), save_as='z1'),
 
     flow = (ParallelFlow().add(blocks.Task(Adder("add"), save_as='z1'),
                            blocks.Task(Adder("add"), save_as='z2'),
+
                              blocks.Task(Adder("add"), save_as='z2'),
                            blocks.Task(Adder("add"), save_as='z3'))
+
                              blocks.Task(Adder("add"), save_as='z3'))
 
This example describes three tasks that will be run in parallel. These tasks accept 'x' and 'y'  parameters and return 'z1', 'z2' and 'z3'.<br />
 
This example describes three tasks that will be run in parallel. These tasks accept 'x' and 'y'  parameters and return 'z1', 'z2' and 'z3'.<br />

Revision as of 10:02, 23 August 2013

Patterns
Patterns describe the Flow structure. Patterns define an order of execution of subblocks (patterns or task blocks). TaskBlocks describe is a block that describes a Task. Task is a user-defined class that can be executed and reverted.

Task is a block that specifies how to execute a used-defined task, what parameters should be used and what data should be saved.

Example:

   class Adder(task.Task):
       def __init__(self, name):
           super(Adder, self).__init__(name)
       def __call__(self, x, y):
           return x+y
       def revert(self, x, y):
           print "Revert adder"
       flow = blocks.Task(Adder("add"), save_as='z')

This example describes an adder that will receive 'x' and 'y' parameters and return 'z'.

LinearFlow pattern runs subblocks sequentially, one after another.

Example:

   flow = (LinearFlow().add(blocks.Task(Adder("add"), save_as='z1'),
                            blocks.Task(Adder("add"), save_as='z2'),
                            blocks.Task(Adder("add"), save_as='z3', args=['z1', 'z2']))

This example describes three tasks. First two adders will receive both 'x' and 'y' parameters and return 'z1' and 'z2'. The third task will receive 'z1' and 'z2' and return 'z3'.

ParallelFlow runs subblocks in parallel and waits for completion.

Example:

   flow = (ParallelFlow().add(blocks.Task(Adder("add"), save_as='z1'),
                              blocks.Task(Adder("add"), save_as='z2'),
                              blocks.Task(Adder("add"), save_as='z3'))

This example describes three tasks that will be run in parallel. These tasks accept 'x' and 'y' parameters and return 'z1', 'z2' and 'z3'.