-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
205 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
|
||
namespace Tzkt.Api.Services | ||
{ | ||
class DumbHealthCheck : IHealthCheck | ||
{ | ||
public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken ct = default) | ||
{ | ||
return Task.FromResult(HealthCheckResult.Healthy()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Tzkt.Api.Services | ||
{ | ||
class HealthChecksConfig | ||
{ | ||
public bool Enabled { get; set; } = false; | ||
public string Endpoint { get; set; } = "/health"; | ||
} | ||
|
||
static class HealthChecksConfigExt | ||
{ | ||
public static HealthChecksConfig GetHealthChecksConfig(this IConfiguration config) | ||
{ | ||
return config.GetSection("HealthChecks")?.Get<HealthChecksConfig>() ?? new(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
{ | ||
"HealthChecks": { | ||
"Enabled": false | ||
}, | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Debug", | ||
"System": "Information", | ||
"Microsoft": "Information" | ||
}, | ||
"Console": { | ||
"FormatterName": "simple", | ||
"FormatterOptions": { | ||
"TimestampFormat": "HH:mm:ss.fff ", | ||
"UseUtcTimestamp": false | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
|
||
namespace Tzkt.Sync.Services | ||
{ | ||
class DumbHealthCheck : IHealthCheck | ||
{ | ||
public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken ct = default) | ||
{ | ||
return Task.FromResult(HealthCheckResult.Healthy()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
|
||
namespace Tzkt.Sync.Services | ||
{ | ||
class HealthCheckPublisher : IHealthCheckPublisher | ||
{ | ||
readonly string FilePath; | ||
|
||
public HealthCheckPublisher(IConfiguration config) | ||
{ | ||
FilePath = config.GetHealthChecksConfig().FilePath | ||
?? Path.GetTempFileName(); | ||
} | ||
|
||
public Task PublishAsync(HealthReport report, CancellationToken cancellationToken) | ||
{ | ||
if (report.Status == HealthStatus.Healthy) | ||
{ | ||
using var _ = File.Create(FilePath); | ||
} | ||
else if (File.Exists(FilePath)) | ||
{ | ||
File.Delete(FilePath); | ||
} | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Tzkt.Sync.Services | ||
{ | ||
class HealthChecksConfig | ||
{ | ||
public bool Enabled { get; set; } = false; | ||
public int Delay { get; set; } = 10; | ||
public int Period { get; set; } = 10; | ||
public string FilePath { get; set; } = "sync.health"; | ||
} | ||
|
||
static class HealthChecksConfigExt | ||
{ | ||
public static HealthChecksConfig GetHealthChecksConfig(this IConfiguration config) | ||
{ | ||
return config.GetSection("HealthChecks")?.Get<HealthChecksConfig>() ?? new(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
{ | ||
"HealthChecks": { | ||
"Enabled": false | ||
}, | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Debug", | ||
"System": "Information", | ||
"Microsoft": "Information" | ||
}, | ||
"Console": { | ||
"FormatterName": "simple", | ||
"FormatterOptions": { | ||
"TimestampFormat": "HH:mm:ss.fff ", | ||
"UseUtcTimestamp": false | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters