asynq_run.go
1.2 KB
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 task
import (
"fmt"
"github.com/hibiken/asynq"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"os"
"os/signal"
"syscall"
)
func Run() {
defer func() {
if err := recover(); err != nil {
fmt.Println(err)
}
}()
srv := asynq.NewServer(
asynq.RedisClientOpt{Addr: constant.REDIS_ADDRESS},
asynq.Config{Concurrency: 1},
)
h := asynq.NewServeMux()
// ... Register handlers
h.HandleFunc(domain.TaskKeyPatternProductRecordStatics(), HandlerProductRecordStatics)
h.HandleFunc(domain.TaskKeyWorkshopWorkTimeRecordStatics(), WorkshopWorkTimeRecordStatics)
h.HandleFunc(domain.TaskDeviceZkTecoReport(), WorkerAttendanceReport)
h.HandleFunc(domain.TaskDeviceCollection(), WorkshopDataConsumer)
log.Logger.Info("aysnq task start!")
// Run blocks and waits for os signal to terminate the program.
if err := srv.Run(h); err != nil {
log.Logger.Error(err.Error())
}
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGTERM, syscall.SIGINT)
<-sigs // wait for termination signal
log.Logger.Info("aysnq task stopping ...")
srv.Shutdown()
}