-
Notifications
You must be signed in to change notification settings - Fork 13
/
hcjob.go
47 lines (38 loc) · 1.02 KB
/
hcjob.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
39
40
41
42
43
44
45
46
47
package agent
import (
"fmt"
hc "github.com/Axway/agent-sdk/pkg/util/healthcheck"
"github.com/Axway/agent-sdk/pkg/util/log"
)
type healthChecker interface {
Healthcheck(_ string) *hc.Status
}
type centralHealthCheckJob struct {
logger log.FieldLogger
healthChecker healthChecker
}
func newCentralHealthCheckJob(checker healthChecker) *centralHealthCheckJob {
logger := log.NewFieldLogger().WithPackage("agent.sdk").WithComponent("centralHealthCheckJob")
return ¢ralHealthCheckJob{
logger: logger,
healthChecker: checker,
}
}
func (c *centralHealthCheckJob) Execute() error {
return c.check()
}
func (c *centralHealthCheckJob) Status() error {
return c.check()
}
func (c *centralHealthCheckJob) Ready() bool {
return true
}
func (c *centralHealthCheckJob) check() error {
status := c.healthChecker.Healthcheck("")
if status == nil || status.Result != hc.OK {
err := fmt.Errorf("central health check status is not OK")
c.logger.WithError(err).Error(status.Details)
return err
}
return nil
}