Skip to content

Commit

Permalink
Fix batch endpoint call
Browse files Browse the repository at this point in the history
  • Loading branch information
MauAraujo committed May 15, 2024
1 parent f03c132 commit 3842a01
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ require (
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-resty/resty/v2 v2.11.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang-jwt/jwt v3.2.1+incompatible // indirect
github.com/golang-jwt/jwt/v5 v5.0.0 // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/google/s2a-go v0.1.4 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1570,8 +1570,6 @@ github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/polyfloyd/go-errorlint v0.0.0-20210722154253-910bb7978349/go.mod h1:wi9BfjxjF/bwiZ701TzmfKu6UKC357IOAtNr0Td0Lvw=
github.com/porter-dev/api-contracts v0.2.159 h1:Ze4K0rm8p6sRMxaFW4Nb3dJuzz4NEMQ+UMXMtOKKRQ4=
github.com/porter-dev/api-contracts v0.2.159/go.mod h1:VV5BzXd02ZdbWIPLVP+PX3GKawJSGQnxorVT2sUZALU=
github.com/porter-dev/api-contracts v0.2.161 h1:kf1ZcS1032eLabBzjwDs9SVcecXwUxJ2mJUkRl9C8jk=
github.com/porter-dev/api-contracts v0.2.161/go.mod h1:VV5BzXd02ZdbWIPLVP+PX3GKawJSGQnxorVT2sUZALU=
github.com/porter-dev/switchboard v0.0.3 h1:dBuYkiVLa5Ce7059d6qTe9a1C2XEORFEanhbtV92R+M=
Expand Down
12 changes: 6 additions & 6 deletions internal/billing/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func (m LagoClient) IngestEvents(ctx context.Context, subscriptionID string, eve
}

batch := events[i:end]
batchInput := make([]lago.EventInput, len(batch))
var batchInput []lago.EventInput
for i := range batch {
externalSubscriptionID := subscriptionID
if enableSandbox {
Expand All @@ -367,20 +367,20 @@ func (m LagoClient) IngestEvents(ctx context.Context, subscriptionID string, eve
TransactionID: batch[i].TransactionID,
ExternalSubscriptionID: externalSubscriptionID,
Code: batch[i].EventType,
Timestamp: batch[i].Timestamp,
Properties: batch[i].Properties,
}
batchInput = append(batchInput, event)
}

// Retry each batch to make sure all events are ingested
var currentAttempts int
for currentAttempts < defaultMaxRetries {
for currentAttempts := 0; currentAttempts < defaultMaxRetries; currentAttempts++ {
_, lagoErr := m.client.Event().Batch(ctx, &batchInput)
if lagoErr == nil {
return telemetry.Error(ctx, span, fmt.Errorf(lagoErr.ErrorCode), "error sending ingest events to Lago")
if lagoErr != nil {
telemetry.Error(ctx, span, err, "failed to send ingest events")
continue
}
currentAttempts++
break
}

if currentAttempts == defaultMaxRetries {
Expand Down

0 comments on commit 3842a01

Please sign in to comment.