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) report status for app_subscriptions #2955

Closed
wants to merge 2 commits into from
Closed
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
22 changes: 20 additions & 2 deletions exporter/appsubscription_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"time"

"github.com/gobitfly/eth2-beaconchain-explorer/db"
"github.com/gobitfly/eth2-beaconchain-explorer/metrics"
"github.com/gobitfly/eth2-beaconchain-explorer/services"
"github.com/gobitfly/eth2-beaconchain-explorer/types"
"github.com/gobitfly/eth2-beaconchain-explorer/utils"

Expand Down Expand Up @@ -50,6 +52,7 @@ func checkSubscriptions() {
return
}

errors := []error{}
for _, receipt := range receipts {
// TODO: At some point we can drop the loop validator approach for iOS purchases and replace it with
// the notifications approach.
Expand All @@ -63,6 +66,9 @@ func checkSubscriptions() {
valid, err := VerifyReceipt(googleClient, appleClient, receipt)

if err != nil {
metrics.Errors.WithLabelValues("app_subscriptions").Inc()
errors = append(errors, err)

// error might indicate a connection problem, ignore validation response
// for this iteration
if strings.Contains(err.Error(), "expired") {
Expand All @@ -80,7 +86,16 @@ func checkSubscriptions() {
if valid.RejectReason == "invalid_store" {
continue
}
updateValidationState(receipt, valid)
err = updateValidationState(receipt, valid)
if err != nil {
errors = append(errors, err)
}
}

if len(errors) > 0 {
services.ReportStatus("app_subscriptions", fmt.Sprintf("checking app_subscriptions had %d errors", len(errors)), nil)
} else {
services.ReportStatus("app_subscriptions", "Running", nil)
}

logger.WithField("subscriptions", len(receipts)).WithField("duration", time.Since(start)).Info("subscription update completed")
Expand Down Expand Up @@ -350,7 +365,7 @@ func getLegacyAppstoreTransactionIDByReceipt(receipt, premiumPkg string) (string
return "", errors.New("not found")
}

func updateValidationState(receipt *types.PremiumData, validation *VerifyResponse) {
func updateValidationState(receipt *types.PremiumData, validation *VerifyResponse) error {
err := db.UpdateUserSubscription(
nil,
receipt.ID,
Expand All @@ -360,6 +375,7 @@ func updateValidationState(receipt *types.PremiumData, validation *VerifyRespons
)
if err != nil {
fmt.Printf("error updating subscription state %v", err)
return err
}

// in case user upgrades downgrades package (fe on iOS) we can automatically update the product here too
Expand All @@ -370,7 +386,9 @@ func updateValidationState(receipt *types.PremiumData, validation *VerifyRespons
)
if err != nil {
fmt.Printf("error updating subscription product id %v", err)
return err
}
return nil
}

type VerifyResponse struct {
Expand Down
Loading