@@ -3,11 +3,13 @@ package sync
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "strings"
6
7
"time"
7
8
8
9
"github.com/Altinity/docker-sync/config"
9
10
"github.com/Altinity/docker-sync/internal/telemetry"
10
11
"github.com/Altinity/docker-sync/structs"
12
+ "github.com/cenkalti/backoff/v4"
11
13
"github.com/rs/zerolog/log"
12
14
"go.opentelemetry.io/otel/attribute"
13
15
"go.opentelemetry.io/otel/metric"
@@ -38,8 +40,23 @@ func SyncImage(ctx context.Context, image *structs.Image) error {
38
40
}
39
41
}
40
42
41
- if serr := SyncTag (image , tag , pullAuthName , pullAuth ); serr != nil {
42
- errs := multierr .Errors (serr )
43
+ if err := backoff .Retry (func () error {
44
+ if err := SyncTag (image , tag , pullAuthName , pullAuth ); err != nil {
45
+ if strings .Contains (err .Error (), "HAP429" ) {
46
+ log .Warn ().
47
+ Str ("source" , image .Source ).
48
+ Msg ("Rate limited by registry, backing off" )
49
+ return err
50
+ }
51
+
52
+ return backoff .Permanent (err )
53
+ }
54
+
55
+ return nil
56
+ }, backoff .NewExponentialBackOff (
57
+ backoff .WithInitialInterval (1 * time .Minute ),
58
+ )); err != nil {
59
+ errs := multierr .Errors (err )
43
60
if len (errs ) > 0 {
44
61
telemetry .Errors .Add (ctx , int64 (len (errs )),
45
62
metric .WithAttributes (
@@ -56,10 +73,10 @@ func SyncImage(ctx context.Context, image *structs.Image) error {
56
73
log .Error ().
57
74
Errs ("errors" , errs ).
58
75
Msg ("Failed to sync tag" )
59
- }
60
76
61
- merr = multierr .Append (merr , serr )
62
- continue
77
+ merr = multierr .Append (merr , err )
78
+ continue
79
+ }
63
80
}
64
81
lastSyncMap [k ] = time .Now ()
65
82
}
0 commit comments