Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Drain connections for python3-http
Motivation and Context
When used with OpenFaaS Standard/Enterprise, the python3-http template's handler will now ignore SIGTERM allowing the watchdog and Kubernetes to handle the shutdown.
When there are ongoing requests, these will be processed before exiting.
When there are no ongoing requests, the function will exit immediately.
How Has This Been Tested?
Tested with OpenFaaS Standard a long running sleep function which went into a Terminating status. The function continued to execute its sleep for the whole duration, whilst the new replica came online and was ready in the meantime.
This is the same approach tested for the golang-http templates.
After:
Code for function: https://github.com/alexellis/go-long/blob/master/stack.yml#L32
Types of changes
No harm change but may require a minimum Python 3 version. I was able to execute test code with 3.8, which is the lowest we advertise to support:
Example:
The change is being made for Kubiya who needed a graceful drain of long-running functions.
This is not new behaviour and is already used in the Go templates. Over time we will add it to all officially supported templates.
cc @shakedaskayo @koss110 @LucasRoesler
I'll get this merged, if there is feedback, please let me know and I'll be happy to consider making changes from people who are more experienced with Python than myself.
https://github.com/openfaas/golang-http-template/blob/master/template/golang-middleware/main.go#L45