add-server-middleware #3
|
@ -19,6 +19,7 @@ type Config struct {
|
||||||
|
|
||||||
TaskTimeout time.Duration
|
TaskTimeout time.Duration
|
||||||
RetryDelayFunc asynq.RetryDelayFunc
|
RetryDelayFunc asynq.RetryDelayFunc
|
||||||
|
ServerMiddlewares []asynq.MiddlewareFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConfigRedis ...
|
// ConfigRedis ...
|
||||||
|
|
|
@ -12,6 +12,7 @@ type Instance struct {
|
||||||
Client *asynq.Client
|
Client *asynq.Client
|
||||||
Server *asynq.ServeMux
|
Server *asynq.ServeMux
|
||||||
Scheduler *asynq.Scheduler
|
Scheduler *asynq.Scheduler
|
||||||
|
Inspector *asynq.Inspector
|
||||||
|
|
||||||
Config Config
|
Config Config
|
||||||
}
|
}
|
||||||
|
@ -31,6 +32,7 @@ func NewInstance(cfg Config) Instance {
|
||||||
instance.Server = initServer(redisConn, cfg)
|
instance.Server = initServer(redisConn, cfg)
|
||||||
instance.Scheduler = initScheduler(redisConn)
|
instance.Scheduler = initScheduler(redisConn)
|
||||||
instance.Client = initClient(redisConn)
|
instance.Client = initClient(redisConn)
|
||||||
|
instance.Inspector = initInspector(redisConn)
|
||||||
instance.Config = cfg
|
instance.Config = cfg
|
||||||
|
|
||||||
// Return instance
|
// Return instance
|
||||||
|
@ -73,6 +75,9 @@ func initServer(redisConn asynq.RedisClientOpt, cfg Config) *asynq.ServeMux {
|
||||||
|
|
||||||
// Init mux server
|
// Init mux server
|
||||||
mux := asynq.NewServeMux()
|
mux := asynq.NewServeMux()
|
||||||
|
if len(cfg.ServerMiddlewares) > 0 {
|
||||||
|
mux.Use(cfg.ServerMiddlewares...)
|
||||||
|
}
|
||||||
|
|
||||||
// Run server
|
// Run server
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -113,6 +118,10 @@ func initClient(redisConn asynq.RedisClientOpt) *asynq.Client {
|
||||||
return client
|
return client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initInspector(redisConn asynq.RedisClientOpt) *asynq.Inspector {
|
||||||
|
return asynq.NewInspector(redisConn)
|
||||||
|
}
|
||||||
|
|
||||||
// GetInstance ...
|
// GetInstance ...
|
||||||
func GetInstance() Instance {
|
func GetInstance() Instance {
|
||||||
return instance
|
return instance
|
||||||
|
|
Loading…
Reference in New Issue