Add config for the periodic refresh of the videos

This commit is contained in:
Lucas BEE 2017-06-13 12:53:07 +02:00
parent a14bccf75c
commit 74898cbf3f
3 changed files with 23 additions and 13 deletions

View File

@ -7,7 +7,9 @@ listen_port: 3000
public_dir: build/public public_dir: build/public
# default prefix, will be served by the go http server # default prefix, will be served by the go http server
img_url_prefix: img/ img_url_prefix: img/
periodic_refresh: 12h periodic_refresh:
enabled: true
interval: 12h
movie: movie:
detailers: detailers:

View File

@ -18,7 +18,7 @@ type Config struct {
Port string `yaml:"listen_port"` Port string `yaml:"listen_port"`
PublicDir string `yaml:"public_dir"` PublicDir string `yaml:"public_dir"`
ImgURLPrefix string `yaml:"img_url_prefix"` ImgURLPrefix string `yaml:"img_url_prefix"`
PeriodicRefresh string `yaml:"periodic_refresh"` PeriodicRefresh PeriodicRefreshConfig `yaml:"periodic_refresh"`
MovieExplorers []polochon.Explorer MovieExplorers []polochon.Explorer
MovieDetailers []polochon.Detailer MovieDetailers []polochon.Detailer
@ -38,6 +38,12 @@ type AuthorizerConfig struct {
Secret string `yaml:"secret"` 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 // Load loads a config file from a path and return a Config object
func Load(path string, log *logrus.Entry) (*Config, error) { func Load(path string, log *logrus.Entry) (*Config, error) {
// Open the file // Open the file

View File

@ -73,12 +73,14 @@ func main() {
// Create the cron object // Create the cron object
c := cron.New() c := cron.New()
if cf.PeriodicRefresh.Enabled {
// Refresh the library every 6h // Refresh the library every 6h
env.Log.Debugf("Running refresh cron every %s", cf.PeriodicRefresh) env.Log.Debugf("Running refresh cron every %s", cf.PeriodicRefresh.Interval)
c.AddFunc(fmt.Sprintf("@every %s", cf.PeriodicRefresh), func() { c.AddFunc(fmt.Sprintf("@every %s", cf.PeriodicRefresh.Interval), func() {
env.Log.Infof("Running refresh cron!") env.Log.Infof("Running refresh cron!")
extmedias.Refresh(env) extmedias.Refresh(env)
}) })
}
// Start the cron // Start the cron
c.Start() c.Start()