File size: 1,071 Bytes
1f10f31 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | package config
import (
"errors"
"time"
"github.com/spf13/viper"
"github.com/openmeterio/openmeter/pkg/errorsx"
"github.com/openmeterio/openmeter/pkg/redis"
)
// ProgressManagerConfiguration stores the configuration parameters for the progress manager
type ProgressManagerConfiguration struct {
Enabled bool
KeyPrefix string
Expiration time.Duration
Redis redis.Config
}
// Validate checks if the configuration is valid
func (c ProgressManagerConfiguration) Validate() error {
var errs []error
if !c.Enabled {
return nil
}
if c.Expiration <= 0 {
errs = append(errs, errors.New("expiration must be greater than 0"))
}
if err := c.Redis.Validate(); err != nil {
errs = append(errs, errorsx.WithPrefix(err, "redis"))
}
return errors.Join(errs...)
}
// ConfigureProgressManager sets the default values for the progress manager configuration
func ConfigureProgressManager(v *viper.Viper) {
v.SetDefault("progressManager.expiration", "5m")
v.SetDefault("progressManager.keyPrefix", "")
redis.Configure(v, "progressManager.redis")
}
|