frontend: refactor submission handlers
This commit is contained in:
parent
fb1d8f90ed
commit
31d98285a4
8 changed files with 184 additions and 187 deletions
55
frontend/settings.go
Normal file
55
frontend/settings.go
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
fronttime "srs.epita.fr/fic-server/frontend/time"
|
||||
"srs.epita.fr/fic-server/settings"
|
||||
)
|
||||
|
||||
const startedFile = "started"
|
||||
|
||||
var touchTimer *time.Timer = nil
|
||||
|
||||
func touchStartedFile() {
|
||||
if fd, err := os.Create(path.Join(SubmissionDir, startedFile)); err == nil {
|
||||
log.Println("Started! Go, Go, Go!!")
|
||||
fd.Close()
|
||||
} else {
|
||||
log.Fatal("Unable to start challenge:", err)
|
||||
}
|
||||
}
|
||||
|
||||
func reloadSettings(config settings.FICSettings) {
|
||||
if fronttime.ChallengeStart != config.Start || fronttime.ChallengeEnd != config.End {
|
||||
if touchTimer != nil {
|
||||
touchTimer.Stop()
|
||||
}
|
||||
startSub := config.Start.Sub(time.Now())
|
||||
if startSub > 0 {
|
||||
log.Println("Challenge will starts at", config.Start, "in", startSub)
|
||||
|
||||
if _, err := os.Stat(path.Join(SubmissionDir, startedFile)); !os.IsNotExist(err) {
|
||||
os.Remove(path.Join(SubmissionDir, startedFile))
|
||||
}
|
||||
|
||||
touchTimer = time.AfterFunc(config.Start.Sub(time.Now().Add(time.Duration(1 * time.Second))), touchStartedFile)
|
||||
} else {
|
||||
log.Println("Challenge started at", config.Start, "since", -startSub)
|
||||
touchStartedFile()
|
||||
}
|
||||
log.Println("Challenge ends on", config.End)
|
||||
|
||||
fronttime.ChallengeStart = config.Start
|
||||
fronttime.ChallengeEnd = config.End
|
||||
} else {
|
||||
log.Println("Configuration reloaded, but start/end times doesn't change.")
|
||||
}
|
||||
|
||||
enableResolutionRoute = config.EnableResolutionRoute
|
||||
denyNameChange = config.DenyNameChange
|
||||
allowRegistration = config.AllowRegistration
|
||||
}
|
||||
Reference in a new issue