예제 #1
0
파일: main.go 프로젝트: adfin/gocelery
func main() {

	var queues = flag.String("queues", "", "queues for running the workers. Use comma to separate multiple queues")
	flag.Parse()

	worker := gocelery.New(&gocelery.Config{
		LogLevel: "info",
		//BrokerURL: "nats://localhost:4222",
		BrokerURL: "redis://localhost:6379",
	})
	defer worker.Close()

	gocelery.RegisterWorker("tasks.add", &Adder{})
	// print all registered workers
	workers := gocelery.RegisteredWorkers()
	for _, worker := range workers {
		log.Debugf("Registered Worker: %s", worker)
	}

	if *queues == "" {
		// start executing
		worker.StartWorkers()
	} else {
		// start executing
		worker.StartWorkersWithQueues(strings.Split(*queues, ","))
	}

}
예제 #2
0
파일: benchmark.go 프로젝트: adfin/gocelery
func main() {
	var count int
	flag.IntVar(&count, "count", 1000, "number of tasks to execute")
	flag.Parse()
	args := []interface{}{12, 32}

	worker := gocelery.New(&gocelery.Config{
		LogLevel: "info",
		//BrokerURL: "nats://localhost:4222",
		BrokerURL: "redis://localhost:6379",
	})
	defer worker.Close()

	log.Info("Benchmarking ")
	var wg sync.WaitGroup
	wg.Add(count)
	start := time.Now()
	for i := 0; i < count; i++ {
		go func(i int) {
			taskResult, err := worker.Enqueue(
				"tasks.add", // task name
				args,        // arguments
				false,       // ignoreResults
			)
			if err == nil {
				<-taskResult
			}
			wg.Done()
		}(i)
	}

	wg.Wait()
	elapsed := time.Since(start)
	log.Infof("%d tasks completed in %f seconds", count, elapsed.Seconds())
}
예제 #3
0
파일: client.go 프로젝트: adfin/gocelery
func main() {
	var queues = flag.String("queue", "", "queue for sending the tasks to.")
	flag.Parse()

	log.Info("We can run the task and ignore result")
	i := 13
	j := 12
	args := []interface{}{i, j}

	worker := gocelery.New(&gocelery.Config{
		LogLevel: "debug",
		//BrokerURL: "nats://localhost:4222",
		BrokerURL: "redis://localhost:6379",
	})
	defer worker.Close()

	worker.Enqueue(
		"tasks.add", // task name
		args,        // arguments
		true,        // ignoreResults
	)

	log.Info("Task Executed.")

	var taskResult chan *gocelery.TaskResult
	if *queues == "" {
		taskResult, _ = worker.Enqueue(
			"tasks.add", // task name
			args,        // arguments
			false,       // ignoreResults
		)
	} else {
		taskResult, _ = worker.EnqueueInQueue(
			*queues,
			"tasks.add", // task name
			args,        // arguments
			false,       // ignoreResults
		)
	}

	tr := <-taskResult
	log.Infof("We can also run the task and return result: %d + %d = %d", i, j, int64(tr.Result.(float64)))
	log.Info("Task Executed.")
}
예제 #4
0
파일: schedule.go 프로젝트: adfin/gocelery
func main() {
	log.Info("Scheduling tasks")

	done := make(chan struct{})

	worker := gocelery.New(&gocelery.Config{
		LogLevel: "debug",
	})
	defer worker.Close()

	i := 13
	j := 12
	taskArgs := []interface{}{i, j}
	if err := worker.EnqueueWithSchedule("*/5 * * * * *", "tasks.add", taskArgs); err != nil {
		log.Error("Failed to enqueue task: ", err)
	}

	log.Info("Scheduler started")
	<-done
}