Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(NOBIDS) remove unneeded retries in stripe-handler #2903

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 7 additions & 18 deletions handlers/stripe.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,12 @@ func StripeWebhook(w http.ResponseWriter, r *http.Request) {
}
now := time.Now()
nowTs := now.Unix()
db.UpdateUserSubscription(tx, appSubID, false, nowTs, "user_canceled")
err = db.UpdateUserSubscription(tx, appSubID, false, nowTs, "user_canceled")
if err != nil {
logger.WithError(err).Error("error updating stripe mobile subscription (sub deleted)", subscription.ID)
http.Error(w, "error updating stripe mobile subscription customer: "+subscription.Customer.ID, http.StatusInternalServerError)
return
}
}

err = tx.Commit()
Expand Down Expand Up @@ -474,23 +479,7 @@ func StripeWebhook(w http.ResponseWriter, r *http.Request) {
}
defer tx.Rollback()

// retry updating subs if webhooks come out of order
retries := 0
for {
err = db.StripeUpdateSubscriptionStatus(tx, invoice.Lines.Data[0].Subscription, true, nil)
if err == nil {
break
}
if err.Error() == "no rows affected" {
retries++
if retries > 3 {
break
}
time.Sleep(1000 * time.Millisecond)
continue
}
break
}
err = db.StripeUpdateSubscriptionStatus(tx, invoice.Lines.Data[0].Subscription, true, nil)
if err != nil {
logger.WithError(err).Error("error processing invoice failed to activate subscription for customer", invoice.Customer.ID)
http.Error(w, "error processing invoice failed to activate subscription for customer", http.StatusInternalServerError)
Expand Down
Loading