admin: heath api now checks untreated files
This commit is contained in:
parent
b4fa57f9c9
commit
a475617657
56
admin/api/health.go
Normal file
56
admin/api/health.go
Normal file
|
@ -0,0 +1,56 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
var TimestampCheck = "submissions"
|
||||
|
||||
func init() {
|
||||
router.GET("/api/timestamps.json", apiHandler(
|
||||
func(httprouter.Params, []byte) (interface{}, error) {
|
||||
if stat, err := os.Stat(TimestampCheck); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
now := time.Now().UTC()
|
||||
return map[string]interface{}{
|
||||
"frontend": stat.ModTime().UTC(),
|
||||
"backend": now,
|
||||
"diffFB": now.Sub(stat.ModTime()),
|
||||
}, nil
|
||||
}
|
||||
}))
|
||||
router.GET("/api/health.json", apiHandler(GetHealth))
|
||||
}
|
||||
|
||||
func getHealth(pathname string) (ret []string) {
|
||||
if ds, err := ioutil.ReadDir(pathname); err != nil {
|
||||
ret = append(ret, fmt.Sprintf("%s: unable to ReadDir: %s", strings.TrimPrefix(pathname, TimestampCheck), err))
|
||||
return
|
||||
} else {
|
||||
for _, d := range ds {
|
||||
p := path.Join(pathname, d.Name())
|
||||
if d.IsDir() && d.Name() != ".tmp" && d.Mode()&os.ModeSymlink == 0 {
|
||||
ret = append(ret, getHealth(p)...)
|
||||
} else if !d.IsDir() && d.Mode()&os.ModeSymlink == 0 {
|
||||
ret = append(ret, fmt.Sprintf("%s/%s: existing untreated file.", strings.TrimPrefix(pathname, TimestampCheck), d.Name()))
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func GetHealth(httprouter.Params, []byte) (interface{}, error) {
|
||||
if _, err := os.Stat(TimestampCheck); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return getHealth(TimestampCheck), nil
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
var TimestampCheck = "submissions"
|
||||
|
||||
func init() {
|
||||
router.GET("/api/timestamps.json", apiHandler(
|
||||
func(httprouter.Params, []byte) (interface{}, error) {
|
||||
if stat, err := os.Stat(TimestampCheck); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
now := time.Now().UTC()
|
||||
return map[string]interface{}{
|
||||
"frontend": stat.ModTime().UTC(),
|
||||
"backend": now,
|
||||
"diffFB": now.Sub(stat.ModTime()),
|
||||
}, nil
|
||||
}
|
||||
}))
|
||||
}
|
Loading…
Reference in New Issue
Block a user