Jump to: navigation, search

Difference between revisions of "TaskFlow/Retry"

(Created page with "Retry is an atom that handles a flow failure and can retry it with another parameters. Retry behavior is similar to the task behavior. Retry can be executed or reverted. But o...")
 
Line 17: Line 17:
 
If tasks 't2' or 't3' fail, then the flow 'f2' will be reverted and retry 'r1' will retry it with the next value from the given collection <code>['a', 'b', 'c']</code>. But if the task 't1' or the task 't4' fails, 'r1' won't retry a flow, because tasks 't1' and 't4' are in the flow 'f1' and don't depend on retry 'r1'.
 
If tasks 't2' or 't3' fail, then the flow 'f2' will be reverted and retry 'r1' will retry it with the next value from the given collection <code>['a', 'b', 'c']</code>. But if the task 't1' or the task 't4' fails, 'r1' won't retry a flow, because tasks 't1' and 't4' are in the flow 'f1' and don't depend on retry 'r1'.
  
If flow with retry has nested flow as it shown in the next example,
+
If a flow with a retry has a nested flow as it shown in the next example,
  
 
   flow = linear_flow.Flow('f1', retry=retry.ForEach(values=['a', 'b', 'c'], name='r1', provides='value').add(
 
   flow = linear_flow.Flow('f1', retry=retry.ForEach(values=['a', 'b', 'c'], name='r1', provides='value').add(

Revision as of 11:29, 20 March 2014

Retry is an atom that handles a flow failure and can retry it with another parameters. Retry behavior is similar to the task behavior. Retry can be executed or reverted. But only one retry can be used in one flow pattern (subflow). If a task from this subflow fails, retry on_failure method is called and retry handles a subflow failure. It can perform three actions:

  • RETRY - retries a subflow again
  • REVERT - reverts only a current subflow, retry of the parent flow can handle this failure
  • REVERT_ALL - completely reverts a whole flow.


The following example shows how retry is used in a flow.

 flow = linear_flow.Flow('f1').add(
     task.Task('t1'),
     linear_flow.Flow('f2', retry=retry.ForEach(values=['a', 'b', 'c'], name='r1', provides='value')).add(
         task.Task('t2'),
         task.Task('t3', requires='value')),
     task.Task('t4'))

In this example the flow 'f2' has a retry controller 'r1', that is a default retry controller retry.ForEach, it accepts a collection of values and iterates over this collection. On each run ForEach retry returns the next value from the collection and stops to retry a subflow if there are no more values left in the collection. If tasks 't2' or 't3' fail, then the flow 'f2' will be reverted and retry 'r1' will retry it with the next value from the given collection ['a', 'b', 'c']. But if the task 't1' or the task 't4' fails, 'r1' won't retry a flow, because tasks 't1' and 't4' are in the flow 'f1' and don't depend on retry 'r1'.

If a flow with a retry has a nested flow as it shown in the next example,

 flow = linear_flow.Flow('f1', retry=retry.ForEach(values=['a', 'b', 'c'], name='r1', provides='value').add(
     task.Task('t1'),
     linear_flow.Flow('f2').add(
         task.Task('t2'),
         task.Task('t3', requires='value')),
     task.Task('t4'))

failure of any task triggers retry 'r1' because all tasks are nested to the flow 'f1' and depend on retry 'r1'.