Jump to: navigation, search

TaskFlow/Patterns and Engines Documentation

< TaskFlow
Revision as of 10:00, 23 August 2013 by Akarpinska (talk | contribs) (Created page with "<big>Patterns</big> <br /> Patterns describe the Flow structure. Patterns define an order of execution of subblocks (patterns or task blocks). TaskBlocks describe is a block ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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'.