Skip to content

Commit f46524f

Browse files
committed
Add retry logic to the enqeuue function
1 parent 29d02eb commit f46524f

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

api/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v1.20.0
1010
github.com/NdoleStudio/go-otelroundtripper v0.0.9
1111
github.com/NdoleStudio/lemonsqueezy-go v1.0.3
12+
github.com/avast/retry-go v3.0.0+incompatible
1213
github.com/carlmjohnson/requests v0.23.5
1314
github.com/cloudevents/sdk-go/v2 v2.14.0
1415
github.com/cockroachdb/cockroach-go/v2 v2.3.5

api/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEq
6060
github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss=
6161
github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU=
6262
github.com/aokoli/goutils v1.0.1/go.mod h1:SijmP0QR8LtwsmDs8Yii5Z/S4trXFGFC2oO5g9DP+DQ=
63+
github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHSxpiH9JdtuBj0=
64+
github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY=
6365
github.com/bsm/ginkgo/v2 v2.7.0/go.mod h1:AiKlXPm7ItEHNc/2+OkrNG4E0ITzojb9/xWzvQ9XZ9w=
6466
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
6567
github.com/bsm/gomega v1.26.0/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=

api/pkg/services/google_cloud_push_queue_service.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"net/http"
77
"time"
88

9+
"github.com/avast/retry-go"
10+
911
cloudtasks "cloud.google.com/go/cloudtasks/apiv2"
1012
"cloud.google.com/go/cloudtasks/apiv2/cloudtaskspb"
1113
"github.com/NdoleStudio/httpsms/pkg/telemetry"
@@ -37,6 +39,15 @@ func NewGooglePushQueue(
3739

3840
// Enqueue a task to the queue
3941
func (queue *googlePushQueue) Enqueue(ctx context.Context, task *PushQueueTask, timeout time.Duration) (queueID string, err error) {
42+
err = retry.Do(func() error {
43+
queueID, err = queue.enqueueImpl(ctx, task, timeout)
44+
return err
45+
}, retry.Attempts(3))
46+
return queueID, err
47+
}
48+
49+
// enqueueImpl a task to the queue
50+
func (queue *googlePushQueue) enqueueImpl(ctx context.Context, task *PushQueueTask, timeout time.Duration) (queueID string, err error) {
4051
ctx, span := queue.tracer.Start(ctx)
4152
defer span.End()
4253

0 commit comments

Comments
 (0)