Skip to content

Commit 2479bf3

Browse files
authored
Merge pull request #40 from datalust/dev
2.1.1 Release
2 parents babfedd + 7f3b19c commit 2479bf3

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/Seq.Input.HealthCheck/HealthCheckInput.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System;
1616
using System.Collections.Generic;
1717
using System.IO;
18+
using System.Linq;
1819
using System.Net.Http;
1920
using Seq.Apps;
2021
using Seq.Input.HealthCheck.Data;
@@ -88,7 +89,8 @@ public void Start(TextWriter inputWriter)
8889
extractor = new JsonDataExtractor(DataExtractionExpression);
8990

9091
var targetUrls = TargetUrl.Split(new[] {'\r', '\n'}, StringSplitOptions.RemoveEmptyEntries);
91-
foreach (var targetUrl in targetUrls)
92+
93+
foreach (var (targetUrl, ix) in targetUrls.Select((t, i) => (t, i)))
9294
{
9395
var healthCheck = new HttpHealthCheck(
9496
_httpClient,
@@ -99,9 +101,14 @@ public void Start(TextWriter inputWriter)
99101
BypassHttpCaching,
100102
FollowRedirects);
101103

104+
var delayStart = targetUrls.Length <= 1
105+
? TimeSpan.Zero
106+
: TimeSpan.FromMilliseconds(((IntervalSeconds * 1000.0) / targetUrls.Length) * ix);
107+
102108
_healthCheckTasks.Add(new HealthCheckTask(
103109
healthCheck,
104110
TimeSpan.FromSeconds(IntervalSeconds),
111+
delayStart,
105112
reporter,
106113
Log));
107114
}
@@ -120,4 +127,4 @@ public void Dispose()
120127

121128
_httpClient?.Dispose();
122129
}
123-
}
130+
}

src/Seq.Input.HealthCheck/HealthCheckTask.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,26 @@ class HealthCheckTask : IDisposable
2424
readonly CancellationTokenSource _cancel = new();
2525
readonly Task _healthCheckTask;
2626

27-
public HealthCheckTask(HttpHealthCheck healthCheck, TimeSpan interval, HealthCheckReporter reporter, ILogger diagnosticLog)
27+
public HealthCheckTask(HttpHealthCheck healthCheck, TimeSpan interval, TimeSpan delayStart, HealthCheckReporter reporter, ILogger diagnosticLog)
2828
{
2929
if (healthCheck == null) throw new ArgumentNullException(nameof(healthCheck));
3030
if (reporter == null) throw new ArgumentNullException(nameof(reporter));
3131

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);
3333
}
3434

3535
static async Task Run(
3636
HttpHealthCheck healthCheck,
37-
TimeSpan interval,
38-
HealthCheckReporter reporter,
37+
TimeSpan interval,
38+
TimeSpan delayStart,
39+
HealthCheckReporter reporter,
3940
ILogger diagnosticLog,
4041
CancellationToken cancel)
4142
{
4243
try
4344
{
45+
if (delayStart > TimeSpan.Zero) await Task.Delay(delayStart, cancel);
46+
4447
while (!cancel.IsCancellationRequested)
4548
{
4649
var result = await healthCheck.CheckNow(cancel);
@@ -74,4 +77,4 @@ public void Dispose()
7477
_cancel.Dispose();
7578
_healthCheckTask.Dispose();
7679
}
77-
}
80+
}

src/Seq.Input.HealthCheck/Seq.Input.HealthCheck.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>net6.0</TargetFramework>
5-
<VersionPrefix>2.1.0</VersionPrefix>
5+
<VersionPrefix>2.1.1</VersionPrefix>
66
<Description>Seq Health Check: periodically GET an HTTP resource and publish response metrics to Seq.</Description>
77
<Authors>Datalust and Contributors</Authors>
88
<PackageTags>seq-app</PackageTags>

0 commit comments

Comments
 (0)