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