本文整理匯總了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,
}
}
}
}