This example shows how to use the retry.lua module to retry operations which might periodically fail. This is very useful to retry periodic failure for susceptible resources like databases and network connections.
Some errors will indicate transitory problems which can be overcome with enough retries. Other errors could indicate fatal conditions requiring the interface to stop. Iguana gives you complete control over identifying errors and implementing your desired response.
If you have any questions please contact us at email@example.com.
Using the Code [top]
- Import the Retry periodic failure channel from the Builtin: Iguana Tools repository
- Experiment with the code to find out how it works
- Then add the module(s) to your Translator project
- Copy the require statement from the channel and add it at the top of your script
Note: This module uses require to return a table containing a single function.
- Adapt the code to your own requirements
- Use the retry.call() function to retry your operation
- Interactive scripting help is included for this module
This is the github code for the main module in the From Translator component:
This is the github code for the main module in the To Translator component:
How it works [top]
The retry module is simple to use. The
retry.call() function retries the specified function call whenever an error occurs. The
retry.call() takes various arguments like: The function to be called, the number of retries, pause (in seconds) and zero or multiple arguments for the function, etc. Also multiple returns from the function are supported.
Our example uses an error function to handles errors returned. It also simulates fatal errors, non-fatal errors and success (no error).
Click to the execute script button a few times to see all these play out:
More information [top]
- Source code for the main module in the From Translator Component on github
- Source code for the main module in the To Translator Component on github
- Source code for the retry.lua module on github
- Source code for the ran.lua module on github
- Retrying unreliable external resources