Exemple #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
}
Exemple #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
}
Exemple #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
}
Exemple #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
}
Exemple #5
0
func ExampleStream_Notify() {
	str, err := stream.New("test_stream", config)
	if err != nil {
		fmt.Printf("ERROR: %s\n", err)
		return
	}

	wg := new(sync.WaitGroup)

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

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

	go WrapWorker(w1, wg)
	go WrapWorker(w2, wg)

	res, err := str.Notify("KILL")
	if err != nil {
		fmt.Printf("ERROR %s\n", err)
		return
	}

	fmt.Printf("CONNECTED WORKERS: %d\n", res)
	wg.Wait()

	// Output:
	// CONNECTED WORKERS: 2
}
Exemple #6
0
package stream_test

import (
	"fmt"
	"github.com/datagentleman/gems/stream"
	"sync"
)

var (
	str, err  = stream.New("test_stream", config)
	output, _ = stream.New("output_test", config)
)

func FullStream(str *stream.Stream, size int) {
	for i := 1; i < size; i++ {
		str.Push(i)
	}

}

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

func ExampleWorker_START_WITH_ACCU() {
	FullStream(str, 10)
	output.Clean()