mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
functions: fix route timeout (#349)
* functions: add route-level timeout configuration options * functions: harmonize defaults
This commit is contained in:
@@ -10,6 +10,10 @@ import (
|
||||
apiErrors "github.com/go-openapi/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultRouteTimeout = 30 // seconds
|
||||
)
|
||||
|
||||
var (
|
||||
ErrRoutesCreate = errors.New("Could not create route")
|
||||
ErrRoutesUpdate = errors.New("Could not update route")
|
||||
@@ -33,6 +37,7 @@ type Route struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
Format string `json:"format,omitempty"`
|
||||
MaxConcurrency int `json:"max_concurrency,omitempty"`
|
||||
Timeout int32 `json:"timeout,omitempty"`
|
||||
Config `json:"config"`
|
||||
}
|
||||
|
||||
@@ -47,6 +52,7 @@ var (
|
||||
ErrRoutesValidationMissingPath = errors.New("Missing route Path")
|
||||
ErrRoutesValidationMissingType = errors.New("Missing route Type")
|
||||
ErrRoutesValidationPathMalformed = errors.New("Path malformed")
|
||||
ErrRoutesValidationNegativeTimeout = errors.New("Negative timeout")
|
||||
)
|
||||
|
||||
func (r *Route) Validate() error {
|
||||
@@ -93,6 +99,12 @@ func (r *Route) Validate() error {
|
||||
r.MaxConcurrency = 1
|
||||
}
|
||||
|
||||
if r.Timeout == 0 {
|
||||
r.Timeout = defaultRouteTimeout
|
||||
} else if r.Timeout < 0 {
|
||||
res = append(res, ErrRoutesValidationNegativeTimeout)
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return apiErrors.CompositeValidationError(res...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user