mirror of
https://github.com/keven1024/015.git
synced 2026-05-26 07:08:02 +00:00
37 lines
604 B
Go
37 lines
604 B
Go
package utils
|
|
|
|
import (
|
|
"github.com/hibiken/asynq"
|
|
)
|
|
|
|
var (
|
|
queueClient *asynq.Client
|
|
queueInspector *asynq.Inspector
|
|
)
|
|
|
|
func InitAsynq() error {
|
|
opt, err := asynq.ParseRedisURI(GetEnv("redis.url"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
queueClient = asynq.NewClient(opt)
|
|
queueInspector = asynq.NewInspector(opt)
|
|
return nil
|
|
}
|
|
|
|
func GetQueueClient() *asynq.Client {
|
|
return queueClient
|
|
}
|
|
|
|
func GetQueueInspector() *asynq.Inspector {
|
|
return queueInspector
|
|
}
|
|
|
|
func RedisURI2AsynqOpt(uri string) asynq.RedisConnOpt {
|
|
opt, err := asynq.ParseRedisURI(uri)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return opt
|
|
}
|