mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Did a little trick to always have one running.
This commit is contained in:
@@ -142,7 +142,7 @@ func ProxyFunc(w http.ResponseWriter, req *http.Request) {
|
|||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
// can't figure out how to compare types so comparing strings.... lame.
|
// can't figure out how to compare types so comparing strings.... lame.
|
||||||
if strings.Contains(etype.String(), "net.OpError") { // == reflect.TypeOf(net.OpError{}) { // couldn't figure out a better way to do this
|
if strings.Contains(etype.String(), "net.OpError") { // == reflect.TypeOf(net.OpError{}) { // couldn't figure out a better way to do this
|
||||||
if len(route.Destinations) > 1 {
|
if len(route.Destinations) > 2 { // always want at least two running
|
||||||
fmt.Println("It's a network error, removing this destination from routing table.")
|
fmt.Println("It's a network error, removing this destination from routing table.")
|
||||||
route.Destinations = append(route.Destinations[:destIndex], route.Destinations[destIndex + 1:]...)
|
route.Destinations = append(route.Destinations[:destIndex], route.Destinations[destIndex + 1:]...)
|
||||||
err := putRoute(route)
|
err := putRoute(route)
|
||||||
@@ -154,7 +154,7 @@ func ProxyFunc(w http.ResponseWriter, req *http.Request) {
|
|||||||
fmt.Println("New route:", route)
|
fmt.Println("New route:", route)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("It's a network error and no other destinations available so we're going to remove it and start new task.")
|
fmt.Println("It's a network error and less than two other workers available so we're going to remove it and start new task.")
|
||||||
route.Destinations = append(route.Destinations[:destIndex], route.Destinations[destIndex + 1:]...)
|
route.Destinations = append(route.Destinations[:destIndex], route.Destinations[destIndex + 1:]...)
|
||||||
err := putRoute(route)
|
err := putRoute(route)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -189,7 +189,7 @@ func startNewWorker(route *Route) (error) {
|
|||||||
fmt.Println("Couldn't marshal json!", err)
|
fmt.Println("Couldn't marshal json!", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
timeout := time.Second*120
|
timeout := time.Second * time.Duration(1800 + rand.Intn(600)) // a little random factor in here to spread out worker deaths
|
||||||
task := worker.Task{
|
task := worker.Task{
|
||||||
CodeName: route.CodeName,
|
CodeName: route.CodeName,
|
||||||
Payload: string(jsonPayload),
|
Payload: string(jsonPayload),
|
||||||
|
|||||||
Reference in New Issue
Block a user