當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Beanstalkd.Quit方法代碼示例

本文整理匯總了Golang中github.com/nutrun/lentil.Beanstalkd.Quit方法的典型用法代碼示例。如果您正苦於以下問題:Golang Beanstalkd.Quit方法的具體用法?Golang Beanstalkd.Quit怎麽用?Golang Beanstalkd.Quit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/nutrun/lentil.Beanstalkd的用法示例。


在下文中一共展示了Beanstalkd.Quit方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Run

// Run is the block's main loop. Here we listen on the different channels we set up.
func (b *ToBeanstalkd) Run() {
	var conn *lentil.Beanstalkd
	var tube = "default"
	var ttr = 0
	var host = ""
	var err error
	for {
		select {
		case msgI := <-b.inrule:
			// set hostname for beanstalkd server
			host, err = util.ParseString(msgI, "Host")
			if err != nil {
				b.Error(err.Error())
				continue
			}
			// set tube name
			tube, err = util.ParseString(msgI, "Tube")
			if err != nil {
				b.Error(errors.New("Could not parse tube name, setting to 'default'"))
				tube = "default"
			}
			// set time to reserve
			ttr, err = util.ParseInt(msgI, "TTR")
			if err != nil || ttr < 0 {
				b.Error(errors.New("Error parsing TTR. Setting TTR to 0"))
				ttr = 0
			}
			// create beanstalkd connection
			conn, err = lentil.Dial(host)
			if err != nil {
				// swallowing a panic from lentil here - streamtools must not die
				b.Error(errors.New("Could not initiate connection with beanstalkd server"))
				continue
			}
			// use the specified tube
			conn.Use(tube)
		case <-b.quit:
			// close connection to beanstalkd and quit
			if conn != nil {
				conn.Quit()
			}
			return
		case msg := <-b.in:
			// deal with inbound data
			msgStr, err := json.Marshal(msg)
			if err != nil {
				b.Error(err)
				continue
			}
			if conn != nil {
				_, err := conn.Put(0, 0, ttr, msgStr)
				if err != nil {
					b.Error(err.Error())
				}
			} else {
				b.Error(errors.New("Beanstalkd connection not initated or lost. Please check your beanstalkd server or block settings."))
			}
		case respChan := <-b.queryrule:
			// deal with a query request
			respChan <- map[string]interface{}{
				"Host": host,
				"Tube": tube,
				"TTR":  ttr,
			}
		}
	}
}
開發者ID:headinthebox,項目名稱:streamtools,代碼行數:68,代碼來源:toBeanstalkd.go


注:本文中的github.com/nutrun/lentil.Beanstalkd.Quit方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。