Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable updating health checks #134

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Src/Metrics/Core/HealthCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public Result(string name, HealthCheckResult check)
}
}

private readonly Func<HealthCheckResult> check;
internal Func<HealthCheckResult> CheckFunc { get; set; }

protected HealthCheck(string name)
: this(name, () => { })
Expand All @@ -33,14 +33,14 @@ public HealthCheck(string name, Func<string> check)
public HealthCheck(string name, Func<HealthCheckResult> check)
{
this.Name = name;
this.check = check;
this.CheckFunc = check;
}

public string Name { get; }

protected virtual HealthCheckResult Check()
{
return this.check();
return this.CheckFunc();
}

public Result Execute()
Expand Down
14 changes: 13 additions & 1 deletion Src/Metrics/HealthChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,19 @@ public static void RegisterHealthCheck(string name, Func<HealthCheckResult> chec
/// <param name="healthCheck">Custom health check to register.</param>
public static void RegisterHealthCheck(HealthCheck healthCheck)
{
checks.TryAdd(healthCheck.Name, healthCheck);
bool added = checks.TryAdd(healthCheck.Name, healthCheck);
if (!added)
{
HealthCheck existingHealthCheck;
if (checks.TryGetValue(healthCheck.Name, out existingHealthCheck))
existingHealthCheck.CheckFunc = healthCheck.CheckFunc;
}
}

public static void UnregisterHealthCheck(string healthCheckName)
{
HealthCheck healthCheck;
checks.TryRemove(healthCheckName, out healthCheck);
}

/// <summary>
Expand Down