本文整理汇总了Golang中github.com/donovanhide/superfastmatch/registry.Registry.Queue方法的典型用法代码示例。如果您正苦于以下问题:Golang Registry.Queue方法的具体用法?Golang Registry.Queue怎么用?Golang Registry.Queue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/donovanhide/superfastmatch/registry.Registry
的用法示例。
在下文中一共展示了Registry.Queue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Start
func Start(registry *registry.Registry) {
glog.Infoln("Starting Queue Processor")
registry.Queue = make(chan bool)
client, err := posting.NewClient(registry)
if err != nil {
panic(err)
}
defer client.Close()
if err = client.Initialise(); err != nil {
panic(err)
}
db := registry.DB()
defer db.Session.Close()
queue := db.C("queue")
registry.Routines.Add(1)
var items QueueItemSlice
for {
start := time.Now()
if err := queue.Find(bson.M{"status": "Queued"}).Sort("_id").Limit(10).All(&items); err != nil {
panic(err)
}
for i, item := range items {
if item.Command != items[0].Command {
items = items[:i]
break
}
}
if err := items.Execute(registry, client); err != nil {
glog.Errorln(err)
}
if len(items) > 0 {
glog.Infof("Executed %d Queue items in %.2f secs", len(items), time.Now().Sub(start).Seconds())
continue
}
select {
case <-registry.Queue:
glog.Infoln("Queue Processor Stopped")
registry.Routines.Done()
return
default:
time.Sleep(time.Second)
}
}
}