Retrieve time through X-FIC-Time header instead of time.json

This commit is contained in:
nemunaire 2018-08-17 22:17:51 +02:00 committed by Pierre-Olivier Mercier
parent c33390fa80
commit 6034246015
11 changed files with 107 additions and 131 deletions

View file

@ -5,13 +5,14 @@ import (
"os"
"time"
fronttime "srs.epita.fr/fic-server/frontend/time"
"srs.epita.fr/fic-server/settings"
)
var startedFile = "started"
var touchTimer *time.Timer = nil
var challengeStart time.Time
var challengeEnd time.Time
func touchStartedFile() {
if fd, err := os.Create(startedFile); err == nil {
@ -23,10 +24,21 @@ func touchStartedFile() {
}
func reloadSettings(config settings.FICSettings) {
if fronttime.ChallengeStart != config.Start || fronttime.ChallengeEnd != config.End {
if challengeStart != config.Start || challengeEnd != config.End {
if touchTimer != nil {
touchTimer.Stop()
}
if config.Start.Unix() == 0 {
log.Println("WARNING: No challenge start defined!")
if _, err := os.Stat(startedFile); !os.IsNotExist(err) {
os.Remove(startedFile)
}
return
}
startSub := config.Start.Sub(time.Now())
if startSub > 0 {
log.Println("Challenge will starts at", config.Start, "in", startSub)
@ -42,8 +54,8 @@ func reloadSettings(config settings.FICSettings) {
}
log.Println("Challenge ends on", config.End)
fronttime.ChallengeStart = config.Start
fronttime.ChallengeEnd = config.End
challengeStart = config.Start
challengeEnd = config.End
} else {
log.Println("Configuration reloaded, but start/end times doesn't change.")
}