mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Catches a zero number exception
This commit is contained in:
@@ -149,7 +149,6 @@ func ProxyFunc(w http.ResponseWriter, req *http.Request) {
|
||||
route, err := getRoute(host)
|
||||
golog.Infoln("route:", route)
|
||||
golog.Infoln("err:", err)
|
||||
// choose random dest
|
||||
if err != nil {
|
||||
common.SendError(w, 400, fmt.Sprintln("Host not registered or error!", err))
|
||||
return
|
||||
@@ -158,6 +157,11 @@ func ProxyFunc(w http.ResponseWriter, req *http.Request) {
|
||||
// common.SendError(w, 400, fmt.Sprintln(w, "Host not configured!"))
|
||||
// return
|
||||
// }
|
||||
|
||||
serveEndpoint(w, req, route)
|
||||
}
|
||||
|
||||
func serveEndpoint(w http.ResponseWriter, req *http.Request, route *Route) {
|
||||
dlen := len(route.Destinations)
|
||||
if dlen == 0 {
|
||||
golog.Infoln("No workers running, starting new task.")
|
||||
@@ -166,14 +170,9 @@ func ProxyFunc(w http.ResponseWriter, req *http.Request) {
|
||||
return
|
||||
}
|
||||
if dlen < 3 {
|
||||
golog.Infoln("Only one worker running, starting a new task.")
|
||||
golog.Infoln("Less than three workers running, starting a new task.")
|
||||
startNewWorker(route)
|
||||
}
|
||||
serveEndpoint(w, req, route)
|
||||
}
|
||||
|
||||
func serveEndpoint(w http.ResponseWriter, req *http.Request, route *Route) {
|
||||
dlen := len(route.Destinations)
|
||||
destIndex := rand.Intn(dlen)
|
||||
destUrlString := route.Destinations[destIndex]
|
||||
// todo: should check if http:// already exists.
|
||||
|
||||
@@ -3,10 +3,11 @@ require 'sinatra'
|
||||
|
||||
# Now we start the actual worker
|
||||
##################################################################3
|
||||
|
||||
ENV['PORT'] = port.to_s # for sinatra
|
||||
|
||||
port = ENV['PORT'].to_i
|
||||
puts "STARTING SINATRA on port #{port}"
|
||||
my_app = Sinatra.new do
|
||||
set :port, port
|
||||
set :port, port
|
||||
get('/') { "hi" }
|
||||
get('/*') { "you passed in #{params[:splat].inspect}" }
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user