mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Not picking up route from cache. wtf
This commit is contained in:
74
checkroute.go
Normal file
74
checkroute.go
Normal file
@@ -0,0 +1,74 @@
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/iron-io/iron_go/cache"
|
||||
"github.com/iron-io/common"
|
||||
|
||||
"encoding/json"
|
||||
"log"
|
||||
)
|
||||
|
||||
var config struct {
|
||||
Iron struct {
|
||||
Token string `json:"token"`
|
||||
ProjectId string `json:"project_id"`
|
||||
SuperToken string `json:"super_token"`
|
||||
Host string `json:"host"`
|
||||
} `json:"iron"`
|
||||
MongoAuth common.MongoConfig `json:"mongo_auth"`
|
||||
Logging struct {
|
||||
To string `json:"to"`
|
||||
Level string `json:"level"`
|
||||
Prefix string `json:"prefix"`
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var icache = cache.New("routing-table")
|
||||
|
||||
func main(){
|
||||
log.Println("STARTING")
|
||||
|
||||
var configFile string
|
||||
var env string
|
||||
env = "development"
|
||||
configFile = "config_" + env + ".json"
|
||||
common.LoadConfig("iron_mq", configFile, &config)
|
||||
common.SetLogLevel(config.Logging.Level)
|
||||
// common.SetLogLocation(config.Logging.To, config.Logging.Prefix)
|
||||
|
||||
host := "routertest.irondns.info"
|
||||
log.Println("CHECKING ROUTE")
|
||||
|
||||
route, err := getRoute(host)
|
||||
log.Println("route:", route)
|
||||
log.Println("err:", err)
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
type Route struct {
|
||||
// TODO: Change destinations to a simple cache so it can expire entries after 55 minutes (the one we use in common?)
|
||||
Host string `json:"host"`
|
||||
Destinations []string `json:"destinations"`
|
||||
ProjectId string `json:"project_id"`
|
||||
Token string `json:"token"` // store this so we can queue up new workers on demand
|
||||
CodeName string `json:"code_name"`
|
||||
}
|
||||
|
||||
|
||||
func getRoute(host string) (*Route, error) {
|
||||
rx, err := icache.Get(host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rx2 := []byte(rx.(string))
|
||||
route := Route{}
|
||||
err = json.Unmarshal(rx2, &route)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &route, err
|
||||
}
|
||||
@@ -57,15 +57,6 @@ func init() {
|
||||
|
||||
}
|
||||
|
||||
type Route struct {
|
||||
// TODO: Change destinations to a simple cache so it can expire entries after 55 minutes (the one we use in common?)
|
||||
Host string `json:"host"`
|
||||
Destinations []string `json:"destinations"`
|
||||
ProjectId string `json:"project_id"`
|
||||
Token string `json:"token"` // store this so we can queue up new workers on demand
|
||||
CodeName string `json:"code_name"`
|
||||
}
|
||||
|
||||
// for adding new hosts
|
||||
type Route2 struct {
|
||||
Host string `json:"host"`
|
||||
@@ -144,7 +135,7 @@ func ProxyFunc(w http.ResponseWriter, req *http.Request) {
|
||||
// 2) This host has active workers so we do the proxy
|
||||
// 3) This host has no active workers so we queue one (or more) up and return a 503 or something with message that says "try again in a minute"
|
||||
// route := routingTable[host]
|
||||
golog.Infoln("getting route for host:", host)
|
||||
golog.Infoln("getting route for host:", host, "--")
|
||||
route, err := getRoute(host)
|
||||
// choose random dest
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user