Skip to content
This repository has been archived by the owner on Nov 16, 2020. It is now read-only.

Commit

Permalink
Topic/ntenczar/update deadline (#584)
Browse files Browse the repository at this point in the history
Updates the timeout functionality to pass a deadline to the funky server. Updates images.yaml to include base images that support this deadline functionality.
  • Loading branch information
tenczar committed Aug 3, 2018
1 parent 8e635bc commit 8de78d3
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,13 @@ All notable changes to this project will be documented in this file. For more in

### Added

- [[Issue #300](https://github.com/vmware/dispatch/issues/300)] **Set timeout on a function** Functions can now be declared
with a timeout using the timeout flag. This timeout is used internally to set a deadline time for function execution. If a
function invocation reaches the function server after the deadline has expired the function will not be invoked. Otherwise
the function will be invoked until the function returns or the deadline is hit, whichever comes first. This support requires
the use of the most recent function base images, 0.0.11 for nodejs-base and python3-base and 0.0.12 for java-base and
powershell-base. Executing `dispatch create seed-images` will automatically populate these images.

### Fixed

### Removed
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/functions.bats
Expand Up @@ -183,8 +183,8 @@ load variables
import sys
def handle(ctx, payload):
print("this goes to stdout")
print("this goes to stderr", file=sys.stderr)
print("this goes to stdout", flush=True)
print("this goes to stderr", file=sys.stderr, flush=True)
EOF

run dispatch create function --image=python3 logger ${src_dir} --handler=logging_test.handle
Expand Down
8 changes: 4 additions & 4 deletions images.yaml
@@ -1,21 +1,21 @@
kind: BaseImage
name: nodejs-base
dockerUrl: dispatchframework/nodejs-base:0.0.9
dockerUrl: dispatchframework/nodejs-base:0.0.12
language: nodejs
---
kind: BaseImage
name: python3-base
dockerUrl: dispatchframework/python3-base:0.0.9
dockerUrl: dispatchframework/python3-base:0.0.12
language: python3
---
kind: BaseImage
name: powershell-base
dockerUrl: dispatchframework/powershell-base:0.0.10
dockerUrl: dispatchframework/powershell-base:0.0.13
language: powershell
---
kind: BaseImage
name: java-base
dockerUrl: dispatchframework/java-base:0.0.10
dockerUrl: dispatchframework/java-base:0.0.13
language: java
---
kind: Image
Expand Down
2 changes: 1 addition & 1 deletion pkg/dispatchcli/cmd/create_function.go
Expand Up @@ -57,7 +57,7 @@ func NewCmdCreateFunction(out io.Writer, errOut io.Writer) *cobra.Command {
cmd.Flags().StringVar(&schemaOutFile, "schema-out", "", "path to file with output validation schema")
cmd.Flags().StringArrayVar(&fnSecrets, "secret", []string{}, "Function secrets, can be specified multiple times or a comma-delimited string")
cmd.Flags().StringArrayVar(&fnServices, "service", []string{}, "Service instances this function uses, can be specified multiple times or a comma-delimited string")
cmd.Flags().Int64Var(&timeout, "timeout", 0, "A timeout to limit function execution time.")
cmd.Flags().Int64Var(&timeout, "timeout", 0, "A timeout to limit function execution time (in milliseconds). Default: 0 (no timeout)")
cmd.MarkFlagRequired("image")
return cmd
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/function-manager/controller.go
Expand Up @@ -297,7 +297,9 @@ func (h *runEntityHandler) Add(ctx context.Context, obj entitystore.Entity) (err
fctx[functions.HTTPContextKey] = run.HTTPContext
}

fctx[functions.TimeoutKey] = f.Timeout
if f.Timeout != 0 {
fctx[functions.DeadlineKey] = time.Now().Add(time.Duration(f.Timeout) * time.Millisecond)
}

output, err := h.Runner.Run(&functions.FunctionExecution{
Context: fctx,
Expand Down
2 changes: 1 addition & 1 deletion pkg/functions/context.go
Expand Up @@ -21,7 +21,7 @@ const (
EventKey = "event"
ErrorKey = "error"
HTTPContextKey = "httpContext"
TimeoutKey = "timeout"
DeadlineKey = "deadline"
)

// Logs returns the logs as a list of strings
Expand Down

0 comments on commit 8de78d3

Please sign in to comment.