mirror of
https://github.com/openfaas/faas.git
synced 2025-06-09 08:46:48 +00:00
Merge pull request #128 from alexellis/more_restarts
Allow restarts of up to 5 times with 5 sec delays
This commit is contained in:
commit
2de58fe7f1
@ -7,7 +7,7 @@ services:
|
||||
- "/var/run/docker.sock:/var/run/docker.sock"
|
||||
ports:
|
||||
- 8080:8080
|
||||
image: functions/gateway:0.6.0
|
||||
image: functions/gateway:0.6.1
|
||||
networks:
|
||||
- functions
|
||||
environment:
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"io/ioutil"
|
||||
|
||||
@ -147,7 +148,7 @@ func MakeDeleteFunctionHandler(metricsOptions metrics.MetricOptions, c *client.C
|
||||
}
|
||||
|
||||
// MakeNewFunctionHandler creates a new function (service) inside the swarm network.
|
||||
func MakeNewFunctionHandler(metricsOptions metrics.MetricOptions, c *client.Client) http.HandlerFunc {
|
||||
func MakeNewFunctionHandler(metricsOptions metrics.MetricOptions, c *client.Client, maxRestarts uint64) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
body, _ := ioutil.ReadAll(r.Body)
|
||||
@ -175,7 +176,7 @@ func MakeNewFunctionHandler(metricsOptions metrics.MetricOptions, c *client.Clie
|
||||
}
|
||||
options.EncodedRegistryAuth = auth
|
||||
}
|
||||
spec := makeSpec(&request)
|
||||
spec := makeSpec(&request, maxRestarts)
|
||||
|
||||
response, err := c.ServiceCreate(context.Background(), spec, options)
|
||||
if err != nil {
|
||||
@ -185,17 +186,19 @@ func MakeNewFunctionHandler(metricsOptions metrics.MetricOptions, c *client.Clie
|
||||
}
|
||||
}
|
||||
|
||||
func makeSpec(request *requests.CreateFunctionRequest) swarm.ServiceSpec {
|
||||
max := uint64(1)
|
||||
func makeSpec(request *requests.CreateFunctionRequest, maxRestarts uint64) swarm.ServiceSpec {
|
||||
|
||||
nets := []swarm.NetworkAttachmentConfig{
|
||||
{Target: request.Network},
|
||||
}
|
||||
restartDelay := time.Second * 5
|
||||
|
||||
spec := swarm.ServiceSpec{
|
||||
TaskTemplate: swarm.TaskSpec{
|
||||
RestartPolicy: &swarm.RestartPolicy{
|
||||
MaxAttempts: &max,
|
||||
Condition: swarm.RestartPolicyConditionNone,
|
||||
MaxAttempts: &maxRestarts,
|
||||
Condition: swarm.RestartPolicyConditionAny,
|
||||
Delay: &restartDelay,
|
||||
},
|
||||
ContainerSpec: swarm.ContainerSpec{
|
||||
Image: request.Image,
|
||||
|
@ -78,11 +78,13 @@ func main() {
|
||||
faasHandlers.DeleteFunction = makeHandler(reverseProxy, &metricsOptions)
|
||||
|
||||
} else {
|
||||
maxRestarts := uint64(5)
|
||||
|
||||
faasHandlers.Proxy = internalHandlers.MakeProxy(metricsOptions, true, dockerClient, &logger)
|
||||
faasHandlers.RoutelessProxy = internalHandlers.MakeProxy(metricsOptions, true, dockerClient, &logger)
|
||||
faasHandlers.Alert = internalHandlers.MakeAlertHandler(internalHandlers.NewSwarmServiceQuery(dockerClient))
|
||||
faasHandlers.ListFunctions = internalHandlers.MakeFunctionReader(metricsOptions, dockerClient)
|
||||
faasHandlers.DeployFunction = internalHandlers.MakeNewFunctionHandler(metricsOptions, dockerClient)
|
||||
faasHandlers.DeployFunction = internalHandlers.MakeNewFunctionHandler(metricsOptions, dockerClient, maxRestarts)
|
||||
faasHandlers.DeleteFunction = internalHandlers.MakeDeleteFunctionHandler(metricsOptions, dockerClient)
|
||||
|
||||
// This could exist in a separate process - records the replicas of each swarm service.
|
||||
|
Loading…
x
Reference in New Issue
Block a user