Example #1
0
func ExampleAccept_Job() {
	stream, err := stream.New("jobs", conf)
	if err != nil {
		fmt.Printf("ERROR:  %s\n", err)
		return
	}

	stream.Clean()

	job := &Job{Id: "1"}
	params, _ := marshaller.IoReader(job)
	req, _ := http.NewRequest("POST", "/job/1", params)

	newJob := &api.JobHandler{stream}
	resp := httptest.NewRecorder()

	ps := httprouter.Params{
		httprouter.Param{"id", "1"},
	}

	newJob.Create(resp, req, ps)

	qsize := stream.Size()

	fmt.Printf("Resonse code: %d\n", resp.Code)
	fmt.Printf("Jobs in queue: %d\n", qsize)

	// Output:
	// Resonse code: 200
	// Jobs in queue: 1
}
Example #2
0
func ExampleStream_Push() {
	stream, err := stream.New("test", config)
	if err != nil {
		fmt.Printf("ERROR: %s\n", err)
		return
	}

	stream.Clean()

	err = stream.Push(item)
	if err != nil {
		fmt.Printf("ERROR: %s\n", err)
		return
	}

	fmt.Printf("%d", stream.Size())

	// Output:
	// 1
}
Example #3
0
func ExampleStream_Pull_1() {
	stream, _ := stream.New("Users", config)
	user := User{"damian"}

	stream.Clean()

	stream.Push(user)
	stream.Push(user)
	stream.Push(user)
	stream.Push(user)

	for {
		_, err := stream.Pull()
		if err != nil {
			fmt.Printf("ERR: %s\n", err)
			break
		}
	}

	// Output:
	// ERR: redigo: nil returned
}
Example #4
0
func ExampleStream_Pull() {
	stream, _ := stream.New("Users", config)
	user := User{"damian"}

	stream.Clean()
	stream.Push(user)
	stream.Push(user)

	for i := 1; i <= 2; i++ {
		if _, err := stream.Pull(); err != nil {
			fmt.Printf("%s\n")
		}

		fmt.Printf("ok\n")
	}

	fmt.Printf("Size: %d", stream.Size())

	// Output:
	//
	// ok
	// ok
	// Size: 0
}