mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Starts a new task if only one destination found.
This commit is contained in:
@@ -110,7 +110,7 @@ func ProxyFunc(w http.ResponseWriter, req *http.Request) {
|
|||||||
route, err := getRoute(host)
|
route, err := getRoute(host)
|
||||||
// choose random dest
|
// choose random dest
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.SendError(w, 400, fmt.Sprintln("Host not configured or error!", err))
|
common.SendError(w, 400, fmt.Sprintln("Host not registered or error!", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// if route == nil { // route.Host == "" {
|
// if route == nil { // route.Host == "" {
|
||||||
@@ -120,9 +120,14 @@ func ProxyFunc(w http.ResponseWriter, req *http.Request) {
|
|||||||
dlen := len(route.Destinations)
|
dlen := len(route.Destinations)
|
||||||
if dlen == 0 {
|
if dlen == 0 {
|
||||||
fmt.Println("No workers running, starting new task.")
|
fmt.Println("No workers running, starting new task.")
|
||||||
startNewWorker(route)
|
_ := startNewWorker(route)
|
||||||
|
common.SendError(w, 500, fmt.Sprintln("No workers running, starting them up...", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if dlen == 1 {
|
||||||
|
fmt.Println("Only one worker running, starting a new task.")
|
||||||
|
_ := startNewWorker(route)
|
||||||
|
}
|
||||||
destIndex := rand.Intn(dlen)
|
destIndex := rand.Intn(dlen)
|
||||||
destUrlString := route.Destinations[destIndex]
|
destUrlString := route.Destinations[destIndex]
|
||||||
// todo: should check if http:// already exists.
|
// todo: should check if http:// already exists.
|
||||||
@@ -148,7 +153,7 @@ func ProxyFunc(w http.ResponseWriter, req *http.Request) {
|
|||||||
err := putRoute(route)
|
err := putRoute(route)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("couldn't update routing table 1", err)
|
fmt.Println("couldn't update routing table 1", err)
|
||||||
common.SendError(w, 400, fmt.Sprintln("couldn't update routing table 1", err))
|
common.SendError(w, 500, fmt.Sprintln("couldn't update routing table 1", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Println("New route:", route)
|
fmt.Println("New route:", route)
|
||||||
@@ -159,14 +164,14 @@ func ProxyFunc(w http.ResponseWriter, req *http.Request) {
|
|||||||
err := putRoute(route)
|
err := putRoute(route)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("couldn't update routing table:", err)
|
fmt.Println("couldn't update routing table:", err)
|
||||||
common.SendError(w, 400, fmt.Sprintln("couldn't update routing table", err))
|
common.SendError(w, 500, fmt.Sprintln("couldn't update routing table", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Println("New route:", route)
|
fmt.Println("New route:", route)
|
||||||
}
|
}
|
||||||
startNewWorker(route)
|
|
||||||
}
|
|
||||||
// start new worker if it's a connection error
|
// start new worker if it's a connection error
|
||||||
|
_ := startNewWorker(route)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Println("Served!")
|
fmt.Println("Served!")
|
||||||
|
|||||||
Reference in New Issue
Block a user