mirror of
https://github.com/neocities/neocities.git
synced 2025-08-26 10:53:26 +02:00
exponential backoff for stripe webhook customer lookup
This commit is contained in:
parent
1695835d53
commit
32256521cf
1 changed files with 13 additions and 1 deletions
|
@ -113,7 +113,19 @@ end
|
||||||
def stripe_get_site_from_event(event)
|
def stripe_get_site_from_event(event)
|
||||||
customer_id = event['data']['object']['customer']
|
customer_id = event['data']['object']['customer']
|
||||||
halt 'ok' if customer_id.nil? # Likely a fraudulent card report
|
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
|
# Some old accounts only have a username for the desc
|
||||||
desc_split = customer.description.split(' - ')
|
desc_split = customer.description.split(' - ')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue