@@ -24,23 +24,26 @@ class HealthCheckTask : IDisposable
24
24
readonly CancellationTokenSource _cancel = new ( ) ;
25
25
readonly Task _healthCheckTask ;
26
26
27
- public HealthCheckTask ( HttpHealthCheck healthCheck , TimeSpan interval , HealthCheckReporter reporter , ILogger diagnosticLog )
27
+ public HealthCheckTask ( HttpHealthCheck healthCheck , TimeSpan interval , TimeSpan delayStart , HealthCheckReporter reporter , ILogger diagnosticLog )
28
28
{
29
29
if ( healthCheck == null ) throw new ArgumentNullException ( nameof ( healthCheck ) ) ;
30
30
if ( reporter == null ) throw new ArgumentNullException ( nameof ( reporter ) ) ;
31
31
32
- _healthCheckTask = Task . Run ( ( ) => Run ( healthCheck , interval , reporter , diagnosticLog , _cancel . Token ) , _cancel . Token ) ;
32
+ _healthCheckTask = Task . Run ( ( ) => Run ( healthCheck , interval , delayStart , reporter , diagnosticLog , _cancel . Token ) , _cancel . Token ) ;
33
33
}
34
34
35
35
static async Task Run (
36
36
HttpHealthCheck healthCheck ,
37
- TimeSpan interval ,
38
- HealthCheckReporter reporter ,
37
+ TimeSpan interval ,
38
+ TimeSpan delayStart ,
39
+ HealthCheckReporter reporter ,
39
40
ILogger diagnosticLog ,
40
41
CancellationToken cancel )
41
42
{
42
43
try
43
44
{
45
+ if ( delayStart > TimeSpan . Zero ) await Task . Delay ( delayStart , cancel ) ;
46
+
44
47
while ( ! cancel . IsCancellationRequested )
45
48
{
46
49
var result = await healthCheck . CheckNow ( cancel ) ;
@@ -74,4 +77,4 @@ public void Dispose()
74
77
_cancel . Dispose ( ) ;
75
78
_healthCheckTask . Dispose ( ) ;
76
79
}
77
- }
80
+ }
0 commit comments