Skip to content

Commit cd51421

Browse files
committed
fix: retry on error listing functions
1 parent d745c72 commit cd51421

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

pkg/function/batch.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,24 @@ const (
2222
)
2323

2424
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
25+
policy := backoff.WithContext(backoff.WithMaxRetries(backoff.NewExponentialBackOff(), maxRetries), ctx)
26+
result, err := backoff.RetryWithData(func() ([]api.FunctionResponse, error) {
27+
resp, err := s.client.V1ListAllFunctionsWithResponse(ctx, s.project)
28+
if err != nil {
29+
return nil, errors.Errorf("failed to list functions: %w", err)
30+
} else if resp.JSON200 == nil {
31+
return nil, errors.Errorf("unexpected list functions status %d: %s", resp.StatusCode(), string(resp.Body))
32+
}
33+
return *resp.JSON200, nil
34+
}, policy)
35+
if err != nil {
36+
return err
3237
}
38+
policy.Reset()
3339
exists := make(map[string]struct{}, len(result))
3440
for _, f := range result {
3541
exists[f.Slug] = struct{}{}
3642
}
37-
policy := backoff.WithContext(backoff.WithMaxRetries(backoff.NewExponentialBackOff(), maxRetries), ctx)
3843
var toUpdate []api.BulkUpdateFunctionBody
3944
OUTER:
4045
for slug, function := range functionConfig {

0 commit comments

Comments
 (0)