Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support function timeout property #537

Merged
merged 2 commits into from
May 29, 2024
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
53 changes: 41 additions & 12 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.

7 changes: 5 additions & 2 deletions go/porcelain/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ type FileBundle struct {

type FunctionMetadata struct {
InvocationMode string
Timeout int64
}

type toolchainSpec struct {
Expand Down Expand Up @@ -536,10 +537,11 @@ func (n *Netlify) uploadFile(ctx context.Context, d *models.Deploy, f *FileBundl

if f.FunctionMetadata != nil {
params = params.WithInvocationMode(&f.FunctionMetadata.InvocationMode)
params = params.WithTimeout(&f.FunctionMetadata.Timeout)
}

if timeout != 0 {
params.SetTimeout(timeout)
params.SetRequestTimeout(timeout)
}
_, operationError = n.Operations.UploadDeployFunction(params, authInfo)
if operationError != nil {
Expand Down Expand Up @@ -797,6 +799,7 @@ func bundleFromManifest(ctx context.Context, manifestFile *os.File, observer Dep

meta := FunctionMetadata{
InvocationMode: function.InvocationMode,
Timeout: function.Timeout,
}
file, err := newFunctionFile(function.Path, fileInfo, runtime, &meta, observer)

Expand All @@ -822,7 +825,7 @@ func bundleFromManifest(ctx context.Context, manifestFile *os.File, observer Dep
}
}

hasConfig := function.DisplayName != "" || function.Generator != "" || len(routes) > 0 || len(function.BuildData) > 0 || function.Priority != 0 || function.TrafficRules != nil
hasConfig := function.DisplayName != "" || function.Generator != "" || len(routes) > 0 || len(function.BuildData) > 0 || function.Priority != 0 || function.TrafficRules != nil || function.Timeout != 0
if hasConfig {
cfg := models.FunctionConfig{
DisplayName: function.DisplayName,
Expand Down
2 changes: 2 additions & 0 deletions go/porcelain/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ func TestBundleWithManifest(t *testing.T) {
"mainFile": "/some/path/hello-js-function-test.js",
"displayName": "Hello Javascript Function",
"generator": "@netlify/[email protected]",
"timeout": 60,
"buildData": { "runtimeAPIVersion": 2 },
"name": "hello-js-function-test",
"schedule": "* * * * *",
Expand Down Expand Up @@ -693,6 +694,7 @@ func TestBundleWithManifest(t *testing.T) {
assert.Equal(t, 3, len(functions.Files))
assert.Equal(t, "a-runtime", functions.Files["hello-js-function-test"].Runtime)
assert.Empty(t, functions.Files["hello-js-function-test"].FunctionMetadata.InvocationMode)
assert.Equal(t, int64(60), functions.Files["hello-js-function-test"].FunctionMetadata.Timeout)
assert.Equal(t, "some-other-runtime", functions.Files["hello-py-function-test"].Runtime)
assert.Equal(t, "stream", functions.Files["hello-py-function-test"].FunctionMetadata.InvocationMode)
assert.Equal(t, "provided.al2", functions.Files["hello-go-binary-function"].Runtime)
Expand Down
1 change: 1 addition & 0 deletions go/porcelain/functions_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type functionsManifestEntry struct {
Schedule string `json:"schedule"`
DisplayName string `json:"displayName"`
Generator string `json:"generator"`
Timeout int64 `json:"timeout"`
BuildData map[string]interface{} `json:"buildData"`
InvocationMode string `json:"invocationMode"`
Routes []functionRoute `json:"routes"`
Expand Down
3 changes: 3 additions & 0 deletions swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,9 @@ paths:
- name: invocation_mode
in: query
type: string
- name: timeout
in: query
type: integer
- name: size
type: integer
in: query
Expand Down
Loading