Not picking up route from cache. wtf

This commit is contained in:
Travis
2013-01-30 13:42:02 -08:00
parent e57435adc1
commit 26072c0cd8
2 changed files with 75 additions and 10 deletions

74
checkroute.go Normal file
View 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
}

View File

@@ -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 {