added graceful fail on categories

This commit is contained in:
Todd Gruben 2014-02-06 07:26:28 -06:00
parent fc87d5e761
commit 7967fc3460

View file

@ -52,14 +52,21 @@ func (self *CategoryFinder) Start() {
connection := config.GetString("category_db_uri")
db, err := sql.Open("mysql", connection)
stmt, err := db.Prepare("select b.category_id from audience_brand b, accounts_tile t where b.id = t.object_id and t.id=?")
if err != nil {
panic(err.Error()) // proper error handling instead of panic in your app
}
cache := lru.New(1000)
defer stmt.Close()
for {
select {
case id := <-self.in:
category := lookup(stmt, id)
category := 0
if err == nil {
category, found := cache.Get(id)
if !found {
category = lookup(stmt, id)
cache.Add(id, category)
}
}
self.out <- category
}
}