-
Notifications
You must be signed in to change notification settings - Fork 866
Expand file tree
/
Copy pathAzureEventGridHealthCheck.cs
More file actions
33 lines (28 loc) · 1.03 KB
/
AzureEventGridHealthCheck.cs
File metadata and controls
33 lines (28 loc) · 1.03 KB
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
namespace HealthChecks.Azure.Messaging.EventGrid;
public sealed class AzureEventGridHealthCheck : IHealthCheck
{
private readonly EventGridPublisherClient _client;
public AzureEventGridHealthCheck(EventGridPublisherClient client)
{
_client = Guard.ThrowIfNull(client);
}
/// <inheritdoc />
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
try
{
// Send a ping event to verify connectivity
var healthCheckEvent = new EventGridEvent(
"HealthCheck",
"HealthCheck.Ping",
"1.0",
new { Timestamp = DateTimeOffset.UtcNow });
await _client.SendEventAsync(healthCheckEvent, cancellationToken).ConfigureAwait(false);
return HealthCheckResult.Healthy();
}
catch (Exception ex)
{
return new HealthCheckResult(context.Registration.FailureStatus, exception: ex);
}
}
}