forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.go
39 lines (32 loc) · 1.1 KB
/
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
39
// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package health
// Check is a health check. Returns the health check results and,
// if unhealthy, a non-nil error.
type Check func() (interface{}, error)
// check wraps a Check and a name
type check struct {
name string
checkFn Check
}
// Name is the identifier for this check and must be unique among all Checks
func (c *check) Name() string { return c.name }
// Execute performs the health check. It returns nil if the check passes.
// It can also return additional information to marshal and display to the caller
func (c *check) Execute() (interface{}, error) { return c.checkFn() }
// monotonicCheck is a check that will run until it passes once, and after that it will
// always pass without performing any logic. Used for bootstrapping, for example.
type monotonicCheck struct {
passed bool
check
}
func (mc *monotonicCheck) Execute() (interface{}, error) {
if mc.passed {
return nil, nil
}
details, pass := mc.check.Execute()
if pass == nil {
mc.passed = true
}
return details, pass
}