Retry on Error
There may be cases when you would like to attempt to run a step again if its execution has failed for whatever reason. For example, if the job takes input data from an online file, there is a possibility that the network is down or the service is unavailable at the exact moment when the job runs. To make it possible to retry in case of an error, FlowForce Server provides the retry count option. By default, this option is 0, which means that the protected block will execute one time only and no retries will be attempted. If you set this option to a value greater than 0, there will be as many attempts to run the whole protected block again when an error is encountered. On each retry, FlowForce discards the results of the previous one and starts execution of the protected block from the beginning. If the maximum number of retries has been reached and the protected block still encounters an error, then the job is considered failed. The error is propagated to the outer block and reported as such only if the maximum number of attempts has been reached and the protected block execution is still unsuccessful.
Consider the following example:
The diagram above illustrates a job that consists of two protected steps (namely, steps A and B benefit from error handling). The Set retry count option is set to 2 (which means "attempt two more times if the first execution was unsuccessful").
Let's suppose that, when the job runs for the first time, step B fails. This means that steps A, B, F will be executed. No error is reported yet, because there are two more attempts left.
On the second attempt, B fails again. This time, steps A, B, D, and F will be executed. The only difference is that now the On Retry block is executed also.
Finally, on the third (and last) attempt, B does no longer encounter an error. This time, steps A, B, D, E, and F will be executed. The job outcome is considered as successful.
If step B had failed on the third attempt, then steps A, B, C, D, and F would have been executed. The job outcome would be considered as failed.
If you need to execute only step B each time when a retry takes place (not both A and B), enclose step B within its own protected block and set the retry count option at this level only. The outer protected block could then have the standard Set retry count = 0.
The number of retries of any given job instance is reported in the FlowForce log. In addition, if you need to get and process the number of retries at run-time, call the retry-count expression function—it returns the number of retries that took place for the innermost protected block surrounding it.
To add an execution step that will be retried multiple times in case of an error:
1.In the job configuration page, click new Error/Success handling step.
2.In the " Execute with error/success handling..." section, enter the number of retries.
3.Click the button under the "Execute with error/success handling..." section and add the actual execution step that is to be retried in case of an error. In the example illustrated below, a job that uploads a file to some FTP server will be re-tried 3 times in case of an error. Note that this is a job defined outside of the current job and called like a function. The implementation details of the called job are not relevant here; any other execution step can be re-tried in a similar manner.
4.Click the button under the mandatory "On error" handler and add an execution step that should be called in case of an error. In this example, a job that writes to a .log file is called in case of an error. Again, this is an external job called like a function, so its implementation details are not shown. For a basic implementation of error logging, see Add Error Handling to a Job.
5.Optionally, add any of the "On Success", "On Retry", or "Always" blocks. To configure such additional handler types, click new error/success handler, select the handler type from the list, and then click to add the required steps under the respective handler.