diff --git a/config.yml.exemple b/config.yml.exemple index 2c2ddb8..5fe090a 100644 --- a/config.yml.exemple +++ b/config.yml.exemple @@ -7,7 +7,9 @@ listen_port: 3000 public_dir: build/public # default prefix, will be served by the go http server img_url_prefix: img/ -periodic_refresh: 12h +periodic_refresh: + enabled: true + interval: 12h movie: detailers: diff --git a/src/internal/config/canape.go b/src/internal/config/canape.go index 5d8780a..5493631 100644 --- a/src/internal/config/canape.go +++ b/src/internal/config/canape.go @@ -13,12 +13,12 @@ import ( // Config represents the Config of the canape app type Config struct { - Authorizer AuthorizerConfig `yaml:"authorizer"` - PGDSN string `yaml:"pgdsn"` - Port string `yaml:"listen_port"` - PublicDir string `yaml:"public_dir"` - ImgURLPrefix string `yaml:"img_url_prefix"` - PeriodicRefresh string `yaml:"periodic_refresh"` + Authorizer AuthorizerConfig `yaml:"authorizer"` + PGDSN string `yaml:"pgdsn"` + Port string `yaml:"listen_port"` + PublicDir string `yaml:"public_dir"` + ImgURLPrefix string `yaml:"img_url_prefix"` + PeriodicRefresh PeriodicRefreshConfig `yaml:"periodic_refresh"` MovieExplorers []polochon.Explorer MovieDetailers []polochon.Detailer @@ -38,6 +38,12 @@ type AuthorizerConfig struct { Secret string `yaml:"secret"` } +// PeriodicRefreshConfig is the config for the periodic refresh +type PeriodicRefreshConfig struct { + Enabled bool `yaml:"enabled"` + Interval string `yaml:"interval"` +} + // Load loads a config file from a path and return a Config object func Load(path string, log *logrus.Entry) (*Config, error) { // Open the file diff --git a/src/main.go b/src/main.go index d66b2d0..554c46e 100644 --- a/src/main.go +++ b/src/main.go @@ -73,12 +73,14 @@ func main() { // Create the cron object c := cron.New() - // Refresh the library every 6h - env.Log.Debugf("Running refresh cron every %s", cf.PeriodicRefresh) - c.AddFunc(fmt.Sprintf("@every %s", cf.PeriodicRefresh), func() { - env.Log.Infof("Running refresh cron!") - extmedias.Refresh(env) - }) + if cf.PeriodicRefresh.Enabled { + // Refresh the library every 6h + env.Log.Debugf("Running refresh cron every %s", cf.PeriodicRefresh.Interval) + c.AddFunc(fmt.Sprintf("@every %s", cf.PeriodicRefresh.Interval), func() { + env.Log.Infof("Running refresh cron!") + extmedias.Refresh(env) + }) + } // Start the cron c.Start()