bouncer/internal/setup/queue_layer.go

41 lines
1.0 KiB
Go
Raw Normal View History

2023-06-23 19:08:35 +02:00
package setup
import (
"time"
"forge.cadoles.com/cadoles/bouncer/internal/config"
"forge.cadoles.com/cadoles/bouncer/internal/proxy/director"
2023-06-24 01:53:56 +02:00
"forge.cadoles.com/cadoles/bouncer/internal/proxy/director/layer/queue"
queueRedis "forge.cadoles.com/cadoles/bouncer/internal/proxy/director/layer/queue/redis"
2023-06-23 19:08:35 +02:00
"github.com/pkg/errors"
)
func init() {
2023-06-24 01:53:56 +02:00
RegisterLayer(queue.LayerType, setupQueueLayer, queue.RawLayerOptionsSchema)
2023-06-23 19:08:35 +02:00
}
2023-06-24 01:53:56 +02:00
func setupQueueLayer(conf *config.Config) (director.Layer, error) {
adapter, err := newQueueAdapter(conf.Redis)
2023-06-23 19:08:35 +02:00
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
}
2023-06-24 01:53:56 +02:00
func newQueueAdapter(redisConf config.RedisConfig) (queue.Adapter, error) {
rdb := NewSharedClient(redisConf)
2023-06-24 01:53:56 +02:00
return queueRedis.NewAdapter(rdb, 2), nil
}