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


Golang beanstalk.NewTubeSet函数代码示例

本文整理汇总了Golang中github.com/kr/beanstalk.NewTubeSet函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTubeSet函数的具体用法?Golang NewTubeSet怎么用?Golang NewTubeSet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewTubeSet函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: watchIncomingMessages

func (m *beanstalkdPubSub) watchIncomingMessages() {
	if m.connSub == nil {
		return
	}
	// create tubeset for topic
	tubeset := beanstalk.NewTubeSet(m.connSub, m.topic)

watchLoop:
	for {
		select {
		// watch for close signal
		case <-m.c.Done():
			return
		default:
			// get the message
			id, body, err := tubeset.Reserve(time.Minute)
			if err == nil {
				// broadcast it to all subscribers
				m.broadcast(body)
				// simply delete the message
				m.connSub.Delete(id)
				continue
			}

			if err.(beanstalk.ConnError).Err == beanstalk.ErrTimeout {
				// re-reserve
				continue
			} else if err.(beanstalk.ConnError).Err == beanstalk.ErrDeadline {
				time.Sleep(time.Second)
				// re-reserve
				continue
			} else if m.possibleNetworkError(err.(beanstalk.ConnError).Err) {
				// try reconnecting
				for {
					select {
					case <-m.c.Done():
						return
					default:
						<-time.After(time.Second * 3)
						if err := m.dialSubSocket(); err != nil {
							continue
						}
						tubeset = beanstalk.NewTubeSet(m.connSub, m.topic)
						goto watchLoop
					}
				}
			}
		}
	}
}
开发者ID:kadekcipta,项目名称:beanpubsub,代码行数:50,代码来源:manager.go

示例2: buryJobs

func (m *mainFrame) buryJobs() error {
	tubeSet := beanstalk.NewTubeSet(m.c, m.currentTubeName())
	n := 0
	var lastError error

	for {
		id, _, err := tubeSet.Reserve(time.Second)
		if err != nil {
			lastError = lastError
			break
		}
		stats, err := m.c.StatsJob(id)
		if err != nil {
			lastError = err
			break
		}
		pri := strToInt(stats["pri"])
		if err := m.c.Bury(id, uint32(pri)); err != nil {
			lastError = err
			break
		}
		n++
	}
	m.showStatus(fmt.Sprintf("%s: %d jobs buried", m.currentTubeName(), n))

	return lastError
}
开发者ID:hasantayyar,项目名称:beanwalker,代码行数:27,代码来源:frame.go

示例3: Tail

func (c *TailCommand) Tail() error {
	ts := beanstalk.NewTubeSet(c.conn, c.Tube)

	errors := 0
	for {
		if errors > 100 {
			return TooManyErrorsError
		}

		id, body, err := ts.Reserve(time.Hour * 24)
		if err != nil {
			if err.Error() != "reserve-with-timeout: deadline soon" {
				errors++
				fmt.Println("Error", err)
			}

			continue
		}

		if err := c.PrintJob(id, body); err != nil {
			errors++
			fmt.Println("Error", err)
			continue
		}

		if err := c.postPrintAction(id); err != nil {
			return err
		}

		fmt.Println(strings.Repeat("-", 80))
	}

	return nil
}
开发者ID:sunyuantao,项目名称:beanstool,代码行数:34,代码来源:tail.go

示例4: runGet

func runGet(cmd *Command) {
	conn := DialBeanstalk()
	ts := beanstalk.NewTubeSet(conn, strings.Split(*getTubes, ",")...)
	n := *getNum
	w := time.Duration(*getTimeout) * time.Second
	var ok bool
	var action func(*beanstalk.Conn, uint64, []byte)
	if action, ok = Actions[*getAction]; !ok {
		fatal(2, "'%s' isn't a valid action", *getAction)
	}
	if *getAction == "r" && n == 0 {
		// Protect users from themselves
		fatal(2, "Using -n 0 and -x r together causes a tight loop and is disallowed")
	}
	for i := uint64(0); n == 0 || i < n; i++ {
		id, body, err := ts.Reserve(w)
		if err != nil {
			if cerr, ok := err.(beanstalk.ConnError); ok && cerr.Err == beanstalk.ErrTimeout {
				// Only write message if no jobs at all, but exit w/ 0
				if i == 0 {
					writeStderr("No jobs")
				}
				return
			}
			fatal(2, "Error getting job:\n%v", err)
		}
		fmt.Printf("%s\n", body)
		action(conn, id, body)
	}
}
开发者ID:schmichael,项目名称:beanstalkcli,代码行数:30,代码来源:get.go

示例5: main

func main() {
	flag.Parse()
	var tb *beanstalk.TubeSet
	var conn_bs *beanstalk.Conn

	rs_timeout := time.Duration(Settings.BeanstalkdReserveTimeout)
	fail_wait := time.Duration(Settings.FailWait) * time.Second

	conn_bs, e := beanstalk.Dial("tcp", Settings.BeanstalkdAddr)

	if e != nil {
		log.Fatal("failed to connected to beanstalkd", e)
	}

	tb = beanstalk.NewTubeSet(conn_bs, Settings.BeanstalkdTube)

	for {
		// reserve a job
		id, job, e := tb.Reserve(rs_timeout)

		// timeout is valid, anything else is fatal
		if cerr, ok := e.(beanstalk.ConnError); ok && cerr.Err == beanstalk.ErrTimeout {
			time.Sleep(fail_wait)
			continue
		} else if e != nil {
			log.Fatal("failed to reserve job", e)
		} else {
			log.Println("read job id", id, "size", len(job), "bytes")
		}

		// connect to the gor replay server
		conn_gr, e := net.Dial("tcp", Settings.GorReplayAddr)

		if e != nil {
			log.Fatal("failed to connected to gor replay server", e)
			time.Sleep(fail_wait)
		}

		// write to gor replay server
		w, e := conn_gr.Write(job)

		if e != nil {
			log.Fatal("failed to write to", Settings.GorReplayAddr, "error", e)
		} else {
			log.Println("wrote", w, "bytes to", Settings.GorReplayAddr)
		}

		// close connection to gor replay server
		conn_gr.Close()

		// delete the job
		e = conn_bs.Delete(id)

		if e != nil {
			log.Println("failed to delete job id", id, "error", e)
		}
	}
}
开发者ID:r4um,项目名称:nginx-beanstalklog-replay,代码行数:58,代码来源:nginx-beanstalklog-replay.go

示例6: Example_reserveOtherTubeSet

func Example_reserveOtherTubeSet() {
	tubeSet := beanstalk.NewTubeSet(conn, "mytube1", "mytube2")
	id, body, err := tubeSet.Reserve(10 * time.Hour)
	if err != nil {
		panic(err)
	}
	fmt.Println("job", id)
	fmt.Println(string(body))
}
开发者ID:c77cc,项目名称:beanstalk,代码行数:9,代码来源:example_test.go

示例7: newTubeSet

// newTubeSet creates a new tubeSet for a tube name
func newTubeSet(conn *beanstalk.Conn, name string) *tubeSet {
	return &tubeSet{
		consume: beanstalk.NewTubeSet(conn, name),
		publish: &beanstalk.Tube{
			Conn: conn,
			Name: name,
		},
	}
}
开发者ID:joshie,项目名称:lochness,代码行数:10,代码来源:tubes.go

示例8: Open

func (t *BeanWorker) Open(tube string) error {
	conn, err := beanstalk.Dial("tcp", t.address)
	if err != nil {
		return err
	}
	conn.Tube = beanstalk.Tube{conn, tube}
	conn.TubeSet = *beanstalk.NewTubeSet(conn, tube)
	t.conn = conn
	return nil
}
开发者ID:MarinX,项目名称:beanrpc,代码行数:10,代码来源:beanrpc.go

示例9: tubes

func (c *Client) tubes(conn *beanstalk.Conn) map[string]*beanstalk.TubeSet {
	names := []string{"default"}

	if mux, isMux := c.Handler.(*WorkMux); isMux {
		names = mux.Tubes()
	}

	tubes := make(map[string]*beanstalk.TubeSet, len(names))
	for _, name := range names {
		tubes[name] = beanstalk.NewTubeSet(conn, name)
	}

	return tubes
}
开发者ID:jinrenlab,项目名称:workers,代码行数:14,代码来源:client.go

示例10: Reserve

// Reserve and return a job from one of the tubes. If no job is available before time timeout has passed, Reserve returns a ConnError recording ErrTimeout.
func (c *Client) Reserve(timeout time.Duration, tubes ...string) (JobID, []byte, error) {
	err := c.Connect()
	if err != nil {
		return 0, nil, err
	}
	if len(tubes) == 0 {
		tubes = []string{"default"}
	}
	ts := beanstalk.NewTubeSet(c.Conn, tubes...)
	jid, body, err := ts.Reserve(timeout)
	if err != nil {
		return 0, nil, unwrap(err)
	}
	return JobID(jid), body, nil
}
开发者ID:riobard,项目名称:go-beanpod,代码行数:16,代码来源:client.go

示例11: deleteAllFromTube

func deleteAllFromTube(t *beanstalk.Tube) {
	queue := beanstalk.NewTubeSet(t.Conn, t.Name)
	deleted := 0
	for {
		id, _, err := queue.Reserve(3 * time.Second)
		if err != nil {
			break
		}
		if err := t.Conn.Delete(id); err != nil {
			fmt.Println(err)
			continue
		}
		deleted++
	}
	fmt.Printf("%d jobs deleted from %s\n", deleted, t.Name)
}
开发者ID:Ekhvalov,项目名称:beans-cli,代码行数:16,代码来源:beans-cli.go

示例12: NewClient

func NewClient(addr string, tubes []string) (client *Client, err error) {
	var conn *beanstalk.Conn
	if conn, err = beanstalk.Dial("tcp", addr); err != nil {
		return
	}

	conn.TubeSet = *beanstalk.NewTubeSet(conn, tubes...)

	client = &Client{
		conn:           conn,
		mu:             new(sync.Mutex),
		ReserveTimeout: time.Duration(5 * time.Second),
	}

	return
}
开发者ID:jcoene,项目名称:workout,代码行数:16,代码来源:client.go

示例13: Run

// Run consume available job based on tube watched and proceed the task
func (w *ApnsWorker) Run() {
	fmt.Printf("[worker] Starting APNS worker\n")
	tube := beanstalk.NewTubeSet(w.Conn, w.TubeName)
	for {
		id, body, err := tube.Reserve(24 * time.Hour)
		if err != nil {
			panic(err)
		}

		var data Job
		err = json.Unmarshal(body, &data)

		if w.ApnsConn == nil {
			certPem, err := ioutil.ReadFile(data.Config.CertPem)
			if err != nil {
				panic(err)
			}
			keyPem, err := ioutil.ReadFile(data.Config.KeyPem)
			if err != nil {
				panic(err)
			}

			w.ApnsConn, _ = apns.NewAPNSConnection(&apns.APNSConfig{
				CertificateBytes: certPem,
				KeyBytes:         keyPem,
			})

			defer w.ApnsConn.Disconnect()
		}

		customField := make(map[string]interface{})
		customField["type"] = data.Data.PushType

		payload := &apns.Payload{
			Token:        data.Data.DeviceToken,
			AlertText:    data.Data.Alert,
			Sound:        data.Data.Sound,
			Badge:        apns.NewBadgeNumber(1),
			CustomFields: customField,
		}

		w.ApnsConn.SendChannel <- payload

		w.Conn.Delete(id)
	}
}
开发者ID:pistarlabs,项目名称:pusher,代码行数:47,代码来源:apns.go

示例14: get

func get(timeout time.Duration, queues ...string) (*Message, error) {
	conn, err := connection()
	if err != nil {
		return nil, err
	}
	ts := beanstalk.NewTubeSet(conn, queues...)
	id, body, err := ts.Reserve(timeout)
	if err != nil {
		if timeoutRegexp.MatchString(err.Error()) {
			return nil, &timeoutError{timeout: timeout}
		}
		return nil, err
	}
	defer conn.Delete(id)
	r := bytes.NewReader(body)
	var msg Message
	if err = gob.NewDecoder(r).Decode(&msg); err != nil && err != io.EOF {
		return nil, fmt.Errorf("Invalid message: %q", body)
	}
	return &msg, nil
}
开发者ID:ningjh,项目名称:tsuru,代码行数:21,代码来源:beanstalk.go

示例15: Bury

func (c *BuryCommand) Bury() error {
	if err := c.calcNum(); err != nil {
		return err
	}

	if c.Num == 0 {
		fmt.Printf("Empty ready queue at tube %q.\n", c.Tube)
		return nil
	}

	fmt.Printf("Trying to bury %d jobs from %q ...\n", c.Num, c.Tube)

	count := 0
	ts := beanstalk.NewTubeSet(c.conn, c.Tube)
	for count < c.Num {
		id, _, err := ts.Reserve(time.Second)
		if err != nil {
			return err
		}

		s, err := c.conn.StatsJob(id)
		if err != nil {
			return err
		}

		pri, err := strconv.ParseUint(s["pri"], 10, 32)
		if err != nil {
			return err
		}

		if err := c.conn.Bury(id, uint32(pri)); err != nil {
			return err
		}

		count++
	}

	fmt.Printf("Actually buried %d.\n", count)
	return nil
}
开发者ID:kemadz,项目名称:beanstool,代码行数:40,代码来源:bury.go


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