当前位置: 首页>>代码示例>>Golang>>正文


Golang Registry.Queue方法代码示例

本文整理汇总了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)
		}
	}
}
开发者ID:pietergvw,项目名称:superfastmatch,代码行数:44,代码来源:queue.go


注:本文中的github.com/donovanhide/superfastmatch/registry.Registry.Queue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。