William Petit
8d91f646c2
All checks were successful
Cadoles/bouncer/pipeline/head This commit looks good
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package setup
|
|
|
|
import (
|
|
"time"
|
|
|
|
"forge.cadoles.com/cadoles/bouncer/internal/config"
|
|
"forge.cadoles.com/cadoles/bouncer/internal/proxy/director"
|
|
"forge.cadoles.com/cadoles/bouncer/internal/proxy/director/layer/queue"
|
|
queueRedis "forge.cadoles.com/cadoles/bouncer/internal/proxy/director/layer/queue/redis"
|
|
"github.com/pkg/errors"
|
|
"github.com/redis/go-redis/v9"
|
|
)
|
|
|
|
func init() {
|
|
RegisterLayer(queue.LayerType, setupQueueLayer, queue.RawLayerOptionsSchema)
|
|
}
|
|
|
|
func setupQueueLayer(conf *config.Config) (director.Layer, error) {
|
|
adapter, err := newQueueAdapter(conf.Redis)
|
|
if err != nil {
|
|
return nil, errors.WithStack(err)
|
|
}
|
|
|
|
options := []queue.OptionFunc{
|
|
queue.WithTemplateDir(string(conf.Layers.Queue.TemplateDir)),
|
|
}
|
|
|
|
if conf.Layers.Queue.DefaultKeepAlive != nil {
|
|
options = append(options, queue.WithDefaultKeepAlive(time.Duration(*conf.Layers.Queue.DefaultKeepAlive)))
|
|
}
|
|
|
|
return queue.New(
|
|
adapter,
|
|
options...,
|
|
), nil
|
|
}
|
|
|
|
func newQueueAdapter(redisConf config.RedisConfig) (queue.Adapter, error) {
|
|
rdb := redis.NewUniversalClient(&redis.UniversalOptions{
|
|
Addrs: redisConf.Adresses,
|
|
MasterName: string(redisConf.Master),
|
|
})
|
|
|
|
return queueRedis.NewAdapter(rdb, 2), nil
|
|
}
|