Jump to: navigation, search

Difference between revisions of "TaskFlow/Retry"

Line 1: Line 1:
 +
====Usage====
 +
 
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 <code>on_failure</code> method is called and retry handles a subflow failure. It can perform three actions:
 
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 <code>on_failure</code> method is called and retry handles a subflow failure. It can perform three actions:
 
* <code>RETRY</code> - retries a subflow again
 
* <code>RETRY</code> - retries a subflow again
Line 27: Line 29:
  
 
failure of any task triggers retry 'r1' because all tasks are nested to the flow 'f1' and depend on retry 'r1'.
 
failure of any task triggers retry 'r1' because all tasks are nested to the flow 'f1' and depend on retry 'r1'.
 +
 +
====Default retries and examples====
 +
 +
There are some default retry controllers that can be used in most cases.
 +
 +
* <code>AlwaysRevertAll</code> - reverts the whole flow on subflow failure.
 +
 +
    flow = linear_flow.Flow('save_data_to_db_flow', retry=')
 +
 +
* <code>Times</code> - retries a flow a given number of times, returns an attempt number. This retry can be used if some operation should be retried several times with the same parameters.

Revision as of 13:53, 20 March 2014

Usage

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

Default retries and examples

There are some default retry controllers that can be used in most cases.

  • AlwaysRevertAll - reverts the whole flow on subflow failure.
   flow = linear_flow.Flow('save_data_to_db_flow', retry=')
  • Times - retries a flow a given number of times, returns an attempt number. This retry can be used if some operation should be retried several times with the same parameters.