/
main.go
42 lines (35 loc) · 857 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
go_worker "github.com/codingXiang/go-worker"
"github.com/gocraft/work"
"github.com/gomodule/redigo/redis"
"log"
)
//define a custom job
type CustomJob struct {
}
//custom must to implement `Do(job *work.Job) error` function
func (c *CustomJob) Do(job *work.Job) error {
log.Println(job.Name)
return nil
}
func main() {
//make a redis connection pool
redisPool := &redis.Pool{
MaxActive: 5,
MaxIdle: 5,
Wait: true,
Dial: func() (redis.Conn, error) {
return redis.Dial("tcp", ":6379", redis.DialPassword("a12345"))
},
}
//make a worker instance
worker := go_worker.NewWorker(10, "ops", redisPool)
//make a CustomJob instance
customJob := &CustomJob{}
//define job to worker with name, instance and options
worker.AddJob("send_email", customJob, nil)
//start worker
worker.Start()
select {}
}