This is pretty much a no-brainer, but in case you’re in doubt, this is an easy way to retry external connections. This way you don’t automatically halt the application at the slightest network issues.
I’m using Peakium as an example of API connection, but you can do this with pretty much anything as long as you rescue from the right exception type (should only be in case there is connectivity issue).
retries = 1
rescue Peakium::APIConnectionError => e
raise e if retries == 0
retries -= 1
This will retry the connection one time if failing (waiting half a second between tries), and throw the exception if it fails again.
You will just do the call like this:
events = peakium_retry do
Straight forward, and easy.