Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions go/plumbing/operations/upload_deploy_function_parameters.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions go/porcelain/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ func (n *Netlify) uploadFile(ctx context.Context, d *models.Deploy, f *FileBundl
}
}

var retryCount int64 = 0

err := backoff.Retry(func() error {
sharedErr.mutex.Lock()

Expand Down Expand Up @@ -485,6 +487,11 @@ func (n *Netlify) uploadFile(ctx context.Context, d *models.Deploy, f *FileBundl
}
case functionUpload:
params := operations.NewUploadDeployFunctionParams().WithDeployID(d.ID).WithName(f.Name).WithFileBody(f).WithRuntime(&f.Runtime)

if retryCount > 0 {
params = params.WithXNfRetryCount(&retryCount)
}

if timeout != 0 {
params.SetTimeout(timeout)
}
Expand All @@ -504,6 +511,9 @@ func (n *Netlify) uploadFile(ctx context.Context, d *models.Deploy, f *FileBundl
sharedErr.mutex.Unlock()
}
}

retryCount++

return operationError
}, b)

Expand Down
54 changes: 54 additions & 0 deletions go/porcelain/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,60 @@ func TestUploadFiles_Cancelation(t *testing.T) {
require.ErrorIs(t, err, gocontext.Canceled)
}

func TestUploadFunctions_RetryCountHeader(t *testing.T) {
attempts := 0
ctx, cancel := gocontext.WithCancel(gocontext.Background())
t.Cleanup(cancel)

server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
defer func() {
attempts++
}()

rw.Header().Set("Content-Type", "application/json; charset=utf-8")

retryCount := req.Header.Get("X-Nf-Retry-Count")

if attempts == 0 {
require.Empty(t, retryCount)
} else {
require.Equal(t, fmt.Sprint(attempts), retryCount)
}

if attempts <= 2 {
rw.WriteHeader(http.StatusInternalServerError)

return
}

rw.WriteHeader(http.StatusOK)
rw.Write([]byte(`{ "name": "foo" }`))
}))
defer server.Close()

hu, _ := url.Parse(server.URL)
tr := apiClient.NewWithClient(hu.Host, "/api/v1", []string{"http"}, http.DefaultClient)
client := NewRetryable(tr, strfmt.Default, 1)
client.uploadLimit = 1
apiCtx := context.WithAuthInfo(ctx, apiClient.BearerToken("token"))

dir, err := ioutil.TempDir("", "deploy")
functionsPath := filepath.Join(dir, ".netlify", "functions")
os.MkdirAll(functionsPath, os.ModePerm)
require.NoError(t, err)
defer os.RemoveAll(dir)
require.NoError(t, ioutil.WriteFile(filepath.Join(functionsPath, "foo.js"), []byte("module.exports = () => {}"), 0644))

files, _, err := bundle(ctx, functionsPath, mockObserver{})
require.NoError(t, err)
d := &models.Deploy{}
for _, bundle := range files.Files {
d.RequiredFunctions = append(d.RequiredFunctions, bundle.Sum)
}

require.NoError(t, client.uploadFiles(apiCtx, d, files, nil, functionUpload, time.Minute))
}

func TestBundle(t *testing.T) {
functions, schedules, err := bundle(gocontext.Background(), "../internal/data", mockObserver{})

Expand Down
5 changes: 5 additions & 0 deletions swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,7 @@ paths:
type: string
format: binary
required: true
- $ref: '#/parameters/retryCount'
responses:
'200':
description: OK
Expand Down Expand Up @@ -3378,6 +3379,10 @@ parameters:
name: per_page
required: false
in: query
retryCount:
name: X-Nf-Retry-Count
type: integer
in: header
x-tagGroups:
- name: OAuth
tags:
Expand Down