5
5
"context"
6
6
"fmt"
7
7
"io"
8
+ "net/http"
8
9
"os"
9
10
"strings"
10
11
"time"
@@ -22,19 +23,28 @@ const (
22
23
)
23
24
24
25
func (s * EdgeRuntimeAPI ) UpsertFunctions (ctx context.Context , functionConfig config.FunctionConfig , filter ... func (string ) bool ) error {
25
- var result []api.FunctionResponse
26
- if resp , err := s .client .V1ListAllFunctionsWithResponse (ctx , s .project ); err != nil {
27
- return errors .Errorf ("failed to list functions: %w" , err )
28
- } else if resp .JSON200 == nil {
29
- return errors .Errorf ("unexpected list functions status %d: %s" , resp .StatusCode (), string (resp .Body ))
30
- } else {
31
- result = * resp .JSON200
26
+ policy := backoff .WithContext (backoff .WithMaxRetries (backoff .NewExponentialBackOff (), maxRetries ), ctx )
27
+ result , err := backoff .RetryWithData (func () ([]api.FunctionResponse , error ) {
28
+ resp , err := s .client .V1ListAllFunctionsWithResponse (ctx , s .project )
29
+ if err != nil {
30
+ return nil , errors .Errorf ("failed to list functions: %w" , err )
31
+ } else if resp .JSON200 == nil {
32
+ err = errors .Errorf ("unexpected list functions status %d: %s" , resp .StatusCode (), string (resp .Body ))
33
+ if resp .StatusCode () < http .StatusInternalServerError {
34
+ err = & backoff.PermanentError {Err : err }
35
+ }
36
+ return nil , err
37
+ }
38
+ return * resp .JSON200 , nil
39
+ }, policy )
40
+ if err != nil {
41
+ return err
32
42
}
43
+ policy .Reset ()
33
44
exists := make (map [string ]struct {}, len (result ))
34
45
for _ , f := range result {
35
46
exists [f .Slug ] = struct {}{}
36
47
}
37
- policy := backoff .WithContext (backoff .WithMaxRetries (backoff .NewExponentialBackOff (), maxRetries ), ctx )
38
48
var toUpdate []api.BulkUpdateFunctionBody
39
49
OUTER:
40
50
for slug , function := range functionConfig {
0 commit comments