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


Golang beanstalk.Dial函數代碼示例

本文整理匯總了Golang中github.com/kr/beanstalk.Dial函數的典型用法代碼示例。如果您正苦於以下問題:Golang Dial函數的具體用法?Golang Dial怎麽用?Golang Dial使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: createConnection

func (m *mainFrame) createConnection() (*beanstalk.Conn, error) {
	c, err := beanstalk.Dial("tcp", fmt.Sprintf("%s:%d", m.host, m.port))
	if err != nil {
		return nil, err
	}
	return c, nil
}
開發者ID:hasantayyar,項目名稱:beanwalker,代碼行數:7,代碼來源:frame.go

示例2: TestReserveIsParallelAndWaits

func TestReserveIsParallelAndWaits(t *testing.T) {
	count := int32(0)
	tubeName := strconv.Itoa(int(time.Now().Unix()))
	start := time.Now()

	mux := NewWorkMux()
	mux.Handle(tubeName, HandlerFunc(func(job *Job) {
		time.Sleep(time.Second)
		atomic.AddInt32(&count, 1)
		job.Delete()
	}))

	go func() {
		conn, _ := beanstalk.Dial("tcp", "localhost:11300")
		tube := &beanstalk.Tube{Conn: conn, Name: tubeName}
		tube.Put([]byte("job1"), 0, 0, time.Minute)
		tube.Put([]byte("job2"), 0, 0, time.Minute)
		tube.Put([]byte("job3"), 0, 0, time.Minute)
		tube.Put([]byte("job4"), 0, 0, time.Minute)
		tube.Put([]byte("job5"), 0, 0, time.Minute)
		time.Sleep(time.Millisecond * 1100)
		syscall.Kill(syscall.Getpid(), syscall.SIGTERM)
	}()

	ConnectAndWork("tcp", "localhost:11300", mux)

	if count != 5 || time.Since(start) > time.Duration(time.Millisecond*2200) {
		t.Fail()
	}
}
開發者ID:jinrenlab,項目名稱:workers,代碼行數:30,代碼來源:client_test.go

示例3: getTestConn

func getTestConn(t *testing.T) *beanstalk.Conn {
	conn, err := beanstalk.Dial("tcp", "localhost:11300")
	if err != nil {
		t.Fail()
	}
	return conn
}
開發者ID:jinrenlab,項目名稱:workers,代碼行數:7,代碼來源:job_test.go

示例4: Producer

func Producer(fname, tubeName string) {
	if fname == "" || tubeName == "" {
		return
	}

	c, err := beanstalk.Dial("tcp", "127.0.0.1:11300")
	if err != nil {
		panic(err)
	}
	defer c.Close()

	c.Tube.Name = tubeName
	c.TubeSet.Name[tubeName] = true
	fmt.Println(fname, " [Producer] tubeName:", tubeName, " c.Tube.Name:", c.Tube.Name)

	for i := 0; i < 5; i++ {
		msg := fmt.Sprintf("for %s %d", tubeName, i)
		c.Put([]byte(msg), 30, 0, 120*time.Second)
		fmt.Println(fname, " [Producer] beanstalk put body:", msg)
		//time.Sleep(1 * time.Second)
	}

	c.Close()
	fmt.Println("Producer() end.")
}
開發者ID:tianyunchong,項目名稱:golang,代碼行數:25,代碼來源:read.go

示例5: Connect

// Connect to the server
func (c *Client) Connect() (err error) {
	if c.Conn != nil {
		return nil
	}
	c.Conn, err = beanstalk.Dial("tcp", c.addr)
	return err
}
開發者ID:riobard,項目名稱:go-beanpod,代碼行數:8,代碼來源:client.go

示例6: TubesStats

// TubesStats connects to beanstalkd and return a hash of all stats
// for each tube we are watching
//
// Return error if fail to connect to beanstalkd of fail to get stats
// for a specic tube
//
// Panic if a specic stat is not an integer, this should never happen
func TubesStats() (stats map[string]map[string]int, err error) {
	conn, err := beanstalk.Dial("tcp", config.BeanstalkdAddr)
	if err != nil {
		return stats, fmt.Errorf("Failed to connect to beanstalkd: %s", err)
	}
	tubes, err := conn.ListTubes()
	if err != nil {
		return stats, fmt.Errorf("Failed to list tubes: %s", err)
	}
	stats = map[string]map[string]int{}
	for _, tubeName := range tubes {
		if !watchingTube(tubeName) {
			continue
		}
		tube := &beanstalk.Tube{
			Name: tubeName,
			Conn: conn,
		}
		data, err := tube.Stats()
		if err != nil {
			return stats, fmt.Errorf("Failed to get stats for tube %s: %s", tubeName, err)
		}
		stats[tubeName] = map[string]int{
			"buried":   mustInt(data["current-jobs-buried"]),
			"ready":    mustInt(data["current-jobs-ready"]),
			"delayed":  mustInt(data["current-jobs-delayed"]),
			"reserver": mustInt(data["current-jobs-reserved"]),
			"urgent":   mustInt(data["current-jobs-urgent"]),
			"waiting":  mustInt(data["current-waiting"]),
			"total":    mustInt(data["total-jobs"]),
		}
	}
	return stats, nil
}
開發者ID:RealGeeks,項目名稱:beanstalk-statsd,代碼行數:41,代碼來源:main.go

示例7: main

func main() {
	commandArgs, other := parseCommands()
	beansAddr := parseArgs(other)
	c, err := beanstalk.Dial("tcp", beansAddr)
	if err != nil {
		fmt.Printf("Warning: can't connect to beanstalk on %s (use -b arg to specify correct connection addr:port)\n", beansAddr)
	} else {
		defer c.Close()
	}
	if len(commandArgs) == 0 {
		printUsageInfo()
		os.Exit(1)
	}
	switch commandArgs[0] {
	case "help":
		helpCmd(c)
		os.Exit(0)
	case "server-info":
		checkConn(c)
		s, _ := c.Stats()
		fmt.Println("Global server info:\n")
		printStats(s)
	default:
		checkConn(c)
		tubeCmd(c, commandArgs[0], commandArgs[1:])
	}
}
開發者ID:Ekhvalov,項目名稱:beans-cli,代碼行數:27,代碼來源:beans-cli.go

示例8: DialBeanstalk

func DialBeanstalk() *beanstalk.Conn {
	conn, err := beanstalk.Dial("tcp", *beanstalkdAddress)
	if err != nil {
		fatal(1, "Error connecting to beanstalkd:\n%v\n", err)
	}
	return conn
}
開發者ID:schmichael,項目名稱:beanstalkcli,代碼行數:7,代碼來源:beanutil.go

示例9: connection

func connection() (*beanstalk.Conn, error) {
	var (
		addr string
		err  error
	)
	mut.Lock()
	if conn == nil {
		mut.Unlock()
		addr, err = config.GetString("queue-server")
		if err != nil {
			addr = "localhost:11300"
		}
		mut.Lock()
		if conn, err = beanstalk.Dial("tcp", addr); err != nil {
			mut.Unlock()
			return nil, err
		}
	}
	if _, err = conn.ListTubes(); err != nil {
		mut.Unlock()
		conn = nil
		return connection()
	}
	mut.Unlock()
	return conn, err
}
開發者ID:ningjh,項目名稱:tsuru,代碼行數:26,代碼來源:beanstalk.go

示例10: Init

/**
連接隊列
*/
func (beansObj *BeansCon) Init(config [2]string) {
	c, err := beanstalk.Dial(config[0], config[1])
	if err != nil {
		panic(err)
	}
	beansObj.conn = c
}
開發者ID:tianyunchong,項目名稱:golang,代碼行數:10,代碼來源:beans.go

示例11: dialSubSocket

func (m *beanstalkdPubSub) dialSubSocket() error {
	c, err := beanstalk.Dial("tcp", m.address)
	if err != nil {
		return err
	}
	m.connSub = c
	return nil
}
開發者ID:kadekcipta,項目名稱:beanpubsub,代碼行數:8,代碼來源:manager.go

示例12: 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

示例13: connect

func connect(hostname string) *beanstalk.Conn {
	c, err := beanstalk.Dial("tcp", hostname)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Could not connect to %s\n", hostname)
		os.Exit(2)
	}

	return c
}
開發者ID:jda,項目名稱:beanstalk_tools,代碼行數:9,代碼來源:main.go

示例14: dialPubConnection

func (m *beanstalkdPubSub) dialPubConnection() error {
	// open connection for subscription
	c, err := beanstalk.Dial("tcp", m.address)
	if err != nil {
		return err
	}
	m.connPub = c
	return nil
}
開發者ID:kadekcipta,項目名稱:beanpubsub,代碼行數:9,代碼來源:manager.go

示例15: main

func main() {
	c, err := beanstalk.Dial("tcp", "127.0.0.1:11300")
	if err != nil {
		fmt.Println("beanstakd not started")
		os.Exit(1)
	}
	id, err := c.Put([]byte("hello"), 1, 0, 120*time.Second)
	fmt.Println(id, err)
}
開發者ID:cch123,項目名稱:test,代碼行數:9,代碼來源:producer.go


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