From 32256521cf62c9441cb65ba5d567c69f2bc176e9 Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Thu, 14 Aug 2025 16:50:30 -0500 Subject: [PATCH] exponential backoff for stripe webhook customer lookup --- app/webhooks.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/webhooks.rb b/app/webhooks.rb index fea80ed2..0b3ab100 100644 --- a/app/webhooks.rb +++ b/app/webhooks.rb @@ -113,7 +113,19 @@ end def stripe_get_site_from_event(event) customer_id = event['data']['object']['customer'] halt 'ok' if customer_id.nil? # Likely a fraudulent card report - customer = Stripe::Customer.retrieve customer_id + + retries = 0 + begin + customer = Stripe::Customer.retrieve customer_id + rescue Stripe::APIConnectionError, Stripe::RateLimitError => e + retries += 1 + if retries <= 3 + sleep(2 ** retries) # exponential backoff: 2s, 4s, 8s + retry + else + raise e + end + end # Some old accounts only have a username for the desc desc_split = customer.description.split(' - ')