@@ -50,14 +50,15 @@ type HealthStatus struct {
50
50
Connection * string `json:"connection,omitempty"`
51
51
ValideUntil time.Time `json:"-"`
52
52
CacheDuration time.Duration `json:"-"`
53
+ TimeProvider TimeProvider `json:"-"`
53
54
}
54
55
55
56
func (hs * HealthStatus ) hasExpired () bool {
56
- return time .Now ().After (hs .ValideUntil )
57
+ return hs . TimeProvider .Now ().After (hs .ValideUntil )
57
58
}
58
59
59
60
func (hs * HealthStatus ) touch () {
60
- hs .ValideUntil = time .Now ().Add (hs .CacheDuration )
61
+ hs .ValideUntil = hs . TimeProvider .Now ().Add (hs .CacheDuration )
61
62
}
62
63
63
64
func (hs * HealthStatus ) connection (status string ) {
@@ -119,7 +120,7 @@ func (hc *healthchecker) AddHealthChecker(name string, checker BasicChecker) {
119
120
120
121
func (hc * healthchecker ) AddHTTPEndpoint (name string , targetURL string , timeoutDuration time.Duration , expectedStatus int , cacheDuration time.Duration ) {
121
122
hc .logger .Info (context .Background (), "msg" , "Adding HTTP endpoint" , "processor" , name , "url" , targetURL )
122
- hc .AddHealthChecker (name , newHTTPEndpointChecker (name , targetURL , timeoutDuration , expectedStatus , cacheDuration ))
123
+ hc .AddHealthChecker (name , newHTTPEndpointChecker (name , targetURL , timeoutDuration , expectedStatus , cacheDuration , RealTimeProvider {} ))
123
124
}
124
125
125
126
func (hc * healthchecker ) AddHTTPEndpoints (endpoints map [string ]string , timeoutDuration time.Duration , expectedStatus int , cacheDuration time.Duration ) {
@@ -130,12 +131,12 @@ func (hc *healthchecker) AddHTTPEndpoints(endpoints map[string]string, timeoutDu
130
131
131
132
func (hc * healthchecker ) AddDatabase (name string , db HealthDatabase , cacheDuration time.Duration ) {
132
133
hc .logger .Info (context .Background (), "msg" , "Adding database" , "processor" , name )
133
- hc .AddHealthChecker (name , newDatabaseChecker (name , db , cacheDuration ))
134
+ hc .AddHealthChecker (name , newDatabaseChecker (name , db , cacheDuration , RealTimeProvider {} ))
134
135
}
135
136
136
137
func (hc * healthchecker ) AddAuditEventsReporterModule (name string , reporter events.AuditEventsReporterModule , timeout time.Duration , cacheDuration time.Duration ) {
137
138
hc .logger .Info (context .Background (), "msg" , "Adding audit event reporter module" , "processor" , name )
138
- hc .AddHealthChecker (name , newAuditEventsReporterChecker (name , reporter , timeout , cacheDuration , hc .logger ))
139
+ hc .AddHealthChecker (name , newAuditEventsReporterChecker (name , reporter , timeout , cacheDuration , hc .logger , RealTimeProvider {} ))
139
140
}
140
141
141
142
// MakeHandler makes a HTTP handler that returns health check information
0 commit comments