Пример #1
0
func disqueLoop(seq int) {
	pool := disque.NewPool(disque.DialFunc(dial), "localhost:7711")
	c, err := pool.Get()
	if err != nil {
		stress.IncCounter("fail", 1)
		log.Println(err)
		return
	}

	defer c.Close()
	for i := 0; i < loops; i++ {
		_, err = c.Add(disque.AddRequest{
			Job: disque.Job{
				Queue: "demo",
				Data:  []byte(fmt.Sprintf("hello world from %d:%d", seq, i)),
			},
			Delay:   time.Minute,
			Timeout: time.Millisecond * 100,
		})

		if err == nil {
			stress.IncCounter("ok", 1)
		} else {
			if !suppressError {
				log.Println(err)
			}
			stress.IncCounter("fail", 1)
		}
	}
}
Пример #2
0
// Create a new client for the given disque addrs. enqueueTimeout is the amount of time after which
// we fail
func NewClient(enqueueTimeout time.Duration, addrs ...string) *Client {

	pool := disque.NewPool(disque.DialFunc(func(addr string) (redis.Conn, error) {
		return redis.DialTimeout("tcp", addr, enqueueTimeout, enqueueTimeout, enqueueTimeout)
	}), addrs...)

	pool.RefreshNodes()
	pool.RunRefreshLoop()

	return &Client{
		pool:              pool,
		enqueueTimeout:    enqueueTimeout,
		replicationFactor: 0, //TODO
	}
}
Пример #3
0
// Create a new worker that runs numGoroutines concurrently, connecting to disque addrs
func NewWorker(numGoroutines int, addrs ...string) *Worker {

	pool := disque.NewPool(disque.DialFunc(func(addr string) (redis.Conn, error) {
		return redis.Dial("tcp", addr)
	}), addrs...)

	pool.RefreshNodes()
	pool.RunRefreshLoop()

	return &Worker{
		pool:          pool,
		numGoroutines: numGoroutines,
		workchan:      make(chan *Task),
		handlers:      map[string]TaskHandler{},
		stopch:        make(chan bool),
		channels:      []string{},
	}
}
Пример #4
0
// NewChan creates a new disque channel objec with a given name, over a disque cluster with the given addrs.
// If async is true, messages are sent using disque async replication (see disque docs for details)
func NewChan(name string, async bool, addrs ...string) *Chan {
	ret := &Chan{
		sendch: nil,
		rcvch:  nil,
		pool:   disque.NewPool(disque.DialFunc(dial), addrs...),
		name:   name,
		qname:  fmt.Sprintf("__qchan__%s", name),
		async:  async,
		stopch: make(chan bool),
	}

	err := ret.pool.RefreshNodes()
	if err != nil {
		log.Println("Error refreshing nodes: %s", err)
	}

	ret.pool.RunRefreshLoop()
	return ret
}