From 429ac997510101befca2399cdc2add5541b146f9 Mon Sep 17 00:00:00 2001 From: Lucas BEE Date: Mon, 12 Jun 2017 13:58:19 +0200 Subject: [PATCH] Add a config to set the info refresh interval --- config.yml.exemple | 1 + src/internal/config/canape.go | 11 ++++++----- src/main.go | 4 +++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/config.yml.exemple b/config.yml.exemple index a198efb..2c2ddb8 100644 --- a/config.yml.exemple +++ b/config.yml.exemple @@ -7,6 +7,7 @@ listen_port: 3000 public_dir: build/public # default prefix, will be served by the go http server img_url_prefix: img/ +periodic_refresh: 12h movie: detailers: diff --git a/src/internal/config/canape.go b/src/internal/config/canape.go index 07e9648..5d8780a 100644 --- a/src/internal/config/canape.go +++ b/src/internal/config/canape.go @@ -13,11 +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"` + 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"` MovieExplorers []polochon.Explorer MovieDetailers []polochon.Detailer diff --git a/src/main.go b/src/main.go index 9154f6c..d66b2d0 100644 --- a/src/main.go +++ b/src/main.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "net/http" "os" @@ -73,7 +74,8 @@ func main() { c := cron.New() // Refresh the library every 6h - c.AddFunc("@every 6h", func() { + 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) })