Skip to content

Instantly share code, notes, and snippets.

@mfittko
Last active February 24, 2022 09:39
Show Gist options
  • Save mfittko/7dbde1d1a326a54438a0a14e1c6ad8d5 to your computer and use it in GitHub Desktop.
Save mfittko/7dbde1d1a326a54438a0a14e1c6ad8d5 to your computer and use it in GitHub Desktop.
Ruby: Retry API calls
def validate_billing_agreement(billing_agreement_id)
with_retry do
handle_response(client.validate_billing_agreement(billing_agreement_id))&.data
end
end
def with_retry(initial_delay: 0.1, max_seconds: 10)
seconds ||= initial_delay
yield
rescue RuntimeError => e
raise e if seconds > max_seconds
sleep seconds
seconds *= 2
retry
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment