Exemple #1
0
func main() {
	q := jobqueue.New(100)

	q.Register(worker(1))
	q.Register(worker(1))
	q.Register(worker(1))
	q.Register(worker(1))
	q.Register(worker(2))

	q.Start()

	for i := 0; i < 100; i++ {
		job := q.NewJob()
		job.Type = fmt.Sprint(i%3 + 1)
		fmt.Println(job)
		err := q.AddJob(job)
		if err != nil {
			fmt.Fprintln(os.Stderr, err.Error())
		}
	}

	//give all jobs X seconds to run.
	time.Sleep(time.Duration(10) * time.Second)

	//	err := q.StopTimeout(time.Duration(20) * time.Second)
	//	if err != nil {
	//		fmt.Fprintln(os.Stderr, err.Error())
	//	}

	//wait for all routines to finish.
	<-q.Stop()
}
Exemple #2
0
func main() {
	q := jobqueue.New(100)

	q.Register(worker(1))

	q.AddJob(q.NewJobValues("1", "", nil))

	q.Start()

	time.Sleep(time.Duration(2) * time.Second)

	<-q.Stop()
}
Exemple #3
0
func main() {
	q := jobqueue.New(100)

	for i := 0; i < 10; i++ {
		q.Register(worker(1))
	}

	q.Start()

	for i := 0; i < 36000; i++ {
		q.AddJob(q.NewJobValues("1", "", nil))
	}

	time.Sleep(time.Duration(80) * time.Minute)

	<-q.Stop()
}