settings: new option to postpone the activation of the given settings file
This commit is contained in:
parent
8e6b8829ea
commit
9be56fb9a2
5 changed files with 47 additions and 16 deletions
|
@ -35,6 +35,8 @@ type FICSettings struct {
|
|||
End time.Time `json:"end"`
|
||||
// Generation is a value used to regenerate static files.
|
||||
Generation time.Time `json:"generation"`
|
||||
// ActivateTime is the time when the current file should be proceed.
|
||||
ActivateTime time.Time `json:"activateTime"`
|
||||
|
||||
// FirstBlood is the coefficient applied to each first team who solve a challenge.
|
||||
FirstBlood float64 `json:"firstBlood"`
|
||||
|
@ -129,11 +131,7 @@ func LoadAndWatchSettings(settingsPath string, reload func (FICSettings)) {
|
|||
go func(){
|
||||
for range c {
|
||||
log.Println("SIGHUP received, reloading settings...")
|
||||
if config, err := ReadSettings(settingsPath); err != nil {
|
||||
log.Println("ERROR: Unable to read challenge settings:", err)
|
||||
} else {
|
||||
reload(config)
|
||||
}
|
||||
go tryReload(settingsPath, reload)
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -152,11 +150,7 @@ func LoadAndWatchSettings(settingsPath string, reload func (FICSettings)) {
|
|||
case ev := <-watcher.Events:
|
||||
if path.Base(ev.Name) == SettingsFile && ev.Op & fsnotify.Write == fsnotify.Write {
|
||||
log.Println("Settings file changes, reloading it!")
|
||||
if config, err := ReadSettings(settingsPath); err != nil {
|
||||
log.Println("ERROR: Unable to read challenge settings:", err)
|
||||
} else {
|
||||
reload(config)
|
||||
}
|
||||
go tryReload(settingsPath, reload)
|
||||
}
|
||||
case err := <-watcher.Errors:
|
||||
log.Println("watcher error:", err)
|
||||
|
@ -165,3 +159,16 @@ func LoadAndWatchSettings(settingsPath string, reload func (FICSettings)) {
|
|||
}()
|
||||
}
|
||||
}
|
||||
|
||||
func tryReload(settingsPath string, reload func (FICSettings)) {
|
||||
if config, err := ReadSettings(settingsPath); err != nil {
|
||||
log.Println("ERROR: Unable to read challenge settings:", err)
|
||||
} else if time.Until(config.ActivateTime) > 0 {
|
||||
log.Println("Configuration reloading postponed, activating at:", config.ActivateTime)
|
||||
time.Sleep(time.Until(config.ActivateTime))
|
||||
log.Println("Time to activate configuration...")
|
||||
tryReload(settingsPath, reload)
|
||||
} else {
|
||||
reload(config)
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue