mirror of
https://github.com/keven1024/015.git
synced 2026-05-26 07:08:02 +00:00
feat(asynq): implement Asynq initialization and client retrieval functions
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
package utils
|
||||
|
||||
import "github.com/hibiken/asynq"
|
||||
|
||||
func GetQueueClient() *asynq.Client {
|
||||
opt := RedisURI2AsynqOpt(GetEnv("redis.url"))
|
||||
return asynq.NewClient(opt)
|
||||
}
|
||||
|
||||
func GetQueueInspector() *asynq.Inspector {
|
||||
opt := RedisURI2AsynqOpt(GetEnv("redis.url"))
|
||||
return asynq.NewInspector(opt)
|
||||
}
|
||||
|
||||
func RedisURI2AsynqOpt(uri string) asynq.RedisConnOpt {
|
||||
opt, err := asynq.ParseRedisURI(GetEnv("redis.url"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return opt
|
||||
}
|
||||
36
pkg/utils/asynq.go
Normal file
36
pkg/utils/asynq.go
Normal file
@@ -0,0 +1,36 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user