Skip to content
This repository was archived by the owner on Jun 29, 2020. It is now read-only.
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static HealthCheckBuilder AddSqlCheck(this HealthCheckBuilder builder, st
return AddSqlCheck(builder, name, connectionString, builder.DefaultCacheDuration);
}

public static HealthCheckBuilder AddSqlCheck(this HealthCheckBuilder builder, string name, string connectionString, TimeSpan cacheDuration)
public static HealthCheckBuilder AddSqlCheck(this HealthCheckBuilder builder, string name, string connectionString, TimeSpan cacheDuration,string query="SELECT 1", Predicate<int> predicate = (result)=>result==1)
{
builder.AddCheck($"SqlCheck({name})", async () =>
{
Expand All @@ -31,14 +31,13 @@ public static HealthCheckBuilder AddSqlCheck(this HealthCheckBuilder builder, st
using (var command = connection.CreateCommand())
{
command.CommandType = CommandType.Text;
command.CommandText = "SELECT 1";
var result = (int)await command.ExecuteScalarAsync().ConfigureAwait(false);
if (result == 1)
{
return HealthCheckResult.Healthy($"SqlCheck({name}): Healthy");
}
command.CommandText = query;

return HealthCheckResult.Unhealthy($"SqlCheck({name}): Unhealthy");
var result = (int)await command.ExecuteScalarAsync().ConfigureAwait(false);

return predicate(result)
? HealthCheckResult.Healthy($"SqlCheck({name}): Healthy")
: HealthCheckResult.Unhealthy($"SqlCheck({name}): Unhealthy");
}
}
}
Expand Down