6
6
"fmt"
7
7
"io"
8
8
"os"
9
+ "strings"
10
+ "time"
9
11
10
12
"github.com/cenkalti/backoff/v4"
11
13
"github.com/docker/go-units"
@@ -32,6 +34,7 @@ func (s *EdgeRuntimeAPI) UpsertFunctions(ctx context.Context, functionConfig con
32
34
for _ , f := range result {
33
35
exists [f .Slug ] = struct {}{}
34
36
}
37
+ policy := backoff .WithContext (backoff .WithMaxRetries (backoff .NewExponentialBackOff (), maxRetries ), ctx )
35
38
var toUpdate []api.BulkUpdateFunctionBody
36
39
OUTER:
37
40
for slug , function := range functionConfig {
@@ -59,12 +62,16 @@ OUTER:
59
62
}
60
63
functionSize := units .HumanSize (float64 (body .Len ()))
61
64
fmt .Fprintf (os .Stderr , "Deploying Function: %s (script size: %s)\n " , slug , functionSize )
62
- policy := backoff .WithContext (backoff .WithMaxRetries (backoff .NewExponentialBackOff (), maxRetries ), ctx )
63
- result , err := backoff .RetryWithData (upsert , policy )
65
+ result , err := backoff .RetryNotifyWithData (upsert , policy , func (err error , d time.Duration ) {
66
+ if strings .Contains (err .Error (), "Duplicated function slug" ) {
67
+ exists [slug ] = struct {}{}
68
+ }
69
+ })
64
70
if err != nil {
65
71
return err
66
72
}
67
73
toUpdate = append (toUpdate , result )
74
+ policy .Reset ()
68
75
}
69
76
if len (toUpdate ) > 1 {
70
77
if resp , err := s .client .V1BulkUpdateFunctionsWithResponse (ctx , s .project , toUpdate ); err != nil {
0 commit comments