diff --git a/go/plumbing/operations/upload_deploy_function_parameters.go b/go/plumbing/operations/upload_deploy_function_parameters.go index 3cadead4..ee4f6add 100644 --- a/go/plumbing/operations/upload_deploy_function_parameters.go +++ b/go/plumbing/operations/upload_deploy_function_parameters.go @@ -24,7 +24,7 @@ func NewUploadDeployFunctionParams() *UploadDeployFunctionParams { var () return &UploadDeployFunctionParams{ - timeout: cr.DefaultTimeout, + requestTimeout: cr.DefaultTimeout, } } @@ -34,7 +34,7 @@ func NewUploadDeployFunctionParamsWithTimeout(timeout time.Duration) *UploadDepl var () return &UploadDeployFunctionParams{ - timeout: timeout, + requestTimeout: timeout, } } @@ -77,21 +77,23 @@ type UploadDeployFunctionParams struct { Runtime *string /*Size*/ Size *int64 + /*Timeout*/ + Timeout *int64 - timeout time.Duration - Context context.Context - HTTPClient *http.Client + requestTimeout time.Duration + Context context.Context + HTTPClient *http.Client } -// WithTimeout adds the timeout to the upload deploy function params -func (o *UploadDeployFunctionParams) WithTimeout(timeout time.Duration) *UploadDeployFunctionParams { - o.SetTimeout(timeout) +// WithRequestTimeout adds the timeout to the upload deploy function params +func (o *UploadDeployFunctionParams) WithRequestTimeout(timeout time.Duration) *UploadDeployFunctionParams { + o.SetRequestTimeout(timeout) return o } -// SetTimeout adds the timeout to the upload deploy function params -func (o *UploadDeployFunctionParams) SetTimeout(timeout time.Duration) { - o.timeout = timeout +// SetRequestTimeout adds the timeout to the upload deploy function params +func (o *UploadDeployFunctionParams) SetRequestTimeout(timeout time.Duration) { + o.requestTimeout = timeout } // WithContext adds the context to the upload deploy function params @@ -193,10 +195,21 @@ func (o *UploadDeployFunctionParams) SetSize(size *int64) { o.Size = size } +// WithTimeout adds the timeout to the upload deploy function params +func (o *UploadDeployFunctionParams) WithTimeout(timeout *int64) *UploadDeployFunctionParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the upload deploy function params +func (o *UploadDeployFunctionParams) SetTimeout(timeout *int64) { + o.Timeout = timeout +} + // WriteToRequest writes these params to a swagger request func (o *UploadDeployFunctionParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { - if err := r.SetTimeout(o.timeout); err != nil { + if err := r.SetTimeout(o.requestTimeout); err != nil { return err } var res []error @@ -274,6 +287,22 @@ func (o *UploadDeployFunctionParams) WriteToRequest(r runtime.ClientRequest, reg } + if o.Timeout != nil { + + // query param timeout + var qrTimeout int64 + if o.Timeout != nil { + qrTimeout = *o.Timeout + } + qTimeout := swag.FormatInt64(qrTimeout) + if qTimeout != "" { + if err := r.SetQueryParam("timeout", qTimeout); err != nil { + return err + } + } + + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } diff --git a/go/porcelain/deploy.go b/go/porcelain/deploy.go index 7548bb13..595a5023 100644 --- a/go/porcelain/deploy.go +++ b/go/porcelain/deploy.go @@ -127,6 +127,7 @@ type FileBundle struct { type FunctionMetadata struct { InvocationMode string + Timeout int64 } type toolchainSpec struct { @@ -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 { @@ -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) @@ -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, diff --git a/go/porcelain/deploy_test.go b/go/porcelain/deploy_test.go index e596eabf..537a5efd 100644 --- a/go/porcelain/deploy_test.go +++ b/go/porcelain/deploy_test.go @@ -646,6 +646,7 @@ func TestBundleWithManifest(t *testing.T) { "mainFile": "/some/path/hello-js-function-test.js", "displayName": "Hello Javascript Function", "generator": "@netlify/fake-plugin@1.0.0", + "timeout": 60, "buildData": { "runtimeAPIVersion": 2 }, "name": "hello-js-function-test", "schedule": "* * * * *", @@ -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) diff --git a/go/porcelain/functions_manifest.go b/go/porcelain/functions_manifest.go index a8444c3a..2129ebf5 100644 --- a/go/porcelain/functions_manifest.go +++ b/go/porcelain/functions_manifest.go @@ -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"` diff --git a/swagger.yml b/swagger.yml index f34d5200..5196be25 100644 --- a/swagger.yml +++ b/swagger.yml @@ -1478,6 +1478,9 @@ paths: - name: invocation_mode in: query type: string + - name: timeout + in: query + type: integer - name: size type: integer in: query