예제 #1
0
파일: main.go 프로젝트: JalfResi/beanc
func pushCommand(conn *gobeanstalk.Conn) {
	if *tube != "" {
		err := conn.Use(*tube)
		if err != nil {
			log.Printf("Use %s failed\n", *tube)
			log.Fatal(err)
		}
	}

	data, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		log.Println("Stdin read error")
		log.Fatal(err)
	}
	if len(data) < 1 {
		log.Println("Stdin has no data")
		log.Fatal()
	}
	if *verbose {
		fmt.Println(string(data))
	}

	var dataset []string
	if *multiline == true {
		dataset = strings.Split(string(data), "\n")
	} else {
		dataset = append(dataset, string(data))
	}

	for _, job := range dataset {
		if len(job) == 0 { // Skip blank lines
			continue
		}

		_, err = conn.Put([]byte(job), *pri, *delay, *ttr)
		if err != nil {
			log.Println("Put failed")
			log.Fatal(err)
		}
	}
}
예제 #2
0
파일: main.go 프로젝트: JalfResi/beanc
func pullCommand(conn *gobeanstalk.Conn) {
	var tubesToWatch []string = strings.SplitN(*tube, ",", -1)
	var watchDefault bool = false

	for _, tubeName := range tubesToWatch {
		_, err := conn.Watch(tubeName)
		if err != nil {
			log.Printf("Watch %s failed\n", tubeName)
			log.Fatal(err)
		}
		if tubeName == "default" {
			watchDefault = true
		}
	}

	// As beanstalk by default adds the tube 'default' to the
	// connections watch list, we need to remove it from this
	// connections watch list.
	if watchDefault == false {
		_, err := conn.Ignore("default")
		if err != nil {
			log.Print("Ignore 'default' tube failed\n")
			log.Fatal(err)
		}
	}

	j, err := conn.Reserve()
	if err != nil {
		log.Println("Reserve failed")
		log.Fatal(err)
	}

	err = conn.Delete(j.Id)
	if err != nil {
		log.Printf("Delete failed. Job ID: %d\n", j.Id)
		log.Fatal(err)
	}

	os.Stdout.Write(j.Body)
}