Пример #1
0
func main() {
	dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
	if err != nil {
		panic(err)
	}
	os.Setenv("RR_ROOT", dir)

	// database
	rr.InitDb(os.Getenv("DATABASE_URL"))

	gokiq.Workers.RedisPool = redis.NewPool(rr.RedisConnect(os.Getenv("REDIS_URL")), 1)

	gokiq.Workers.PollInterval = 1 * time.Second
	gokiq.Workers.RedisNamespace = "rr"
	gokiq.Workers.WorkerCount = 5

	gokiq.Workers.Register(&rr.UserCallbackJob{})
	gokiq.Workers.Register(&rr.NewAccountEmailJob{})

	gokiq.Workers.Run()
}
Пример #2
0
func Test_ScheduleCallbacks(t *testing.T) {
	pool := redis.NewPool(rr.RedisConnect("redis://localhost:6379/6"), 1)
	gokiq.Client.RedisPool = pool
	gokiq.Client.RedisNamespace = "test"

	conn := pool.Get()
	defer conn.Close()

	conn.Do("del", "test:schedule")

	rids := []int64{1, 2}
	err := rr.ScheduleCallbacks(gokiq.Client, rids, time.Now().UTC(), "http://example.com/webhook")
	if err != nil {
		t.Fatal(err)
	}
	err = rr.ScheduleCallbacks(gokiq.Client, rids, time.Now().UTC(), "http://example.com/webhook")
	if err != nil {
		t.Fatal(err)
	}

	jobs, _ := conn.Do("ZCARD", "test:schedule")

	expect(t, int64(2), jobs)
}