-
Notifications
You must be signed in to change notification settings - Fork 1
/
health_check.go
38 lines (33 loc) · 941 Bytes
/
health_check.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package public
import (
"github.com/Crossbell-Box/OperatorSync/app/server/config"
"github.com/Crossbell-Box/OperatorSync/app/server/consts"
"github.com/gin-gonic/gin"
"net/http"
"time"
)
type healthStatus struct {
OK bool `json:"ok"`
Message string `json:"message,omitempty"`
}
func HealthCheck(ctx *gin.Context) {
if config.Config.IsMainServer {
if time.Now().Sub(config.Status.Jobs.FeedCollectLastRun) > 2*consts.JOBS_INTERVAL_FEED_COLLECT {
ctx.JSON(http.StatusInternalServerError, healthStatus{
OK: false,
Message: "Feed collect work not running",
})
return
}
if time.Now().Sub(config.Status.Jobs.ResumePausedAccountsLastRun) > 2*consts.JOBS_INTERVAL_RESUME_PAUSED_ACCOUNTS {
ctx.JSON(http.StatusInternalServerError, healthStatus{
OK: false,
Message: "Resume paused account work not running",
})
return
}
}
ctx.JSON(http.StatusOK, healthStatus{
OK: true,
})
}