Add tick information to server status

This commit is contained in:
Marc Di Luzio 2020-06-06 16:37:57 +01:00
parent 6ac5a559b5
commit db38ad6091
3 changed files with 16 additions and 4 deletions
cmd/rove
pkg
rove
server

View file

@ -105,6 +105,8 @@ func InnerMain(command string) error {
} else {
fmt.Printf("Ready: %t\n", response.Ready)
fmt.Printf("Version: %s\n", response.Version)
fmt.Printf("Tick: %d\n", response.Tick)
fmt.Printf("Next Tick: %s\n", response.NextTick)
}
case "register":

View file

@ -17,8 +17,10 @@ func (s Server) Status() (r StatusResponse, err error) {
// StatusResponse is a struct that contains information on the status of the server
type StatusResponse struct {
Ready bool `json:"ready"`
Version string `json:"version"`
Ready bool `json:"ready"`
Version string `json:"version"`
Tick int `json:"tick"`
NextTick string `json:"nexttick,omitempty"`
}
// ==============================

View file

@ -59,10 +59,18 @@ var Routes = []Route{
func HandleStatus(s *Server, vars map[string]string, b io.ReadCloser, w io.Writer) (interface{}, error) {
// Simply return the current server status
return rove.StatusResponse{
response := rove.StatusResponse{
Ready: true,
Version: version.Version,
}, nil
Tick: s.tick,
}
// If there's a schedule, respond with it
if len(s.schedule.Entries()) > 0 {
response.NextTick = s.schedule.Entries()[0].Next.Format("15:04:05")
}
return response, nil
}
// HandleRegister handles /register endpoint