Skip to content

Commit

Permalink
fix: retry requests
Browse files Browse the repository at this point in the history
and extended bunny client timeout to 1 minute
  • Loading branch information
skibish committed Oct 29, 2023
1 parent 0db36d8 commit 8ca97d0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ module github.com/skibish/bunnysync
go 1.21.3

require golang.org/x/sync v0.4.0

require github.com/cenkalti/backoff/v4 v4.2.1 // indirect
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
2 changes: 1 addition & 1 deletion internal/bunnyclient/bunnyclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type BunnyClient struct {
storageAPIKey string
}

const bunnyClientTimeout = 10 * time.Second
const bunnyClientTimeout = 60 * time.Second

type ListObjectResponse struct {
Checksum string `json:"Checksum"`
Expand Down
11 changes: 9 additions & 2 deletions internal/statetracker/statetracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"
"sync"

"github.com/cenkalti/backoff/v4"
"github.com/skibish/bunnysync/internal/bunnyclient"
"golang.org/x/sync/errgroup"
)
Expand Down Expand Up @@ -104,7 +105,10 @@ func (s *StateTracker) Sync(ctx context.Context, srcDir string) error {
if !ok || hash != remoteHash {
fmt.Fprintf(s.w, "+ %s\n", correctedFilePath)
if !s.dryRun {
err = s.bc.Upload(ctx, correctedFilePath, b)
op := func() error {
return s.bc.Upload(ctx, correctedFilePath, b)
}
err = backoff.Retry(op, backoff.NewExponentialBackOff())
if err != nil {
return fmt.Errorf("failed to upload %q: %w", correctedFilePath, err)
}
Expand Down Expand Up @@ -146,7 +150,10 @@ func (s *StateTracker) cleanup(ctx context.Context) error {

fmt.Fprintf(s.w, "- %s\n", fname)
if !s.dryRun {
err := s.bc.Delete(ctx, fname)
op := func() error {
return s.bc.Delete(ctx, fname)
}
err := backoff.Retry(op, backoff.NewExponentialBackOff())
if err != nil {
return fmt.Errorf("failed to delete %q: %w", fname, err)
}
Expand Down

0 comments on commit 8ca97d0

Please sign in to comment.