fix log
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
using Dlhis.Middle.Entities;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Mapster;
|
||||
|
||||
namespace Dlhis.Middle.Services.Implements;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace Dlhis.Middle.Services.Implements;
|
||||
|
||||
public class HealthCheckService : IHealthCheckService
|
||||
{
|
||||
private bool _isOffline = false;
|
||||
private bool _isOffline;
|
||||
private readonly string _hostName;
|
||||
private readonly ILogger<HealthCheckService> _logger;
|
||||
private int _successRetry;
|
||||
@@ -23,11 +23,13 @@ public class HealthCheckService : IHealthCheckService
|
||||
|
||||
public async Task DoHealthCheckAsync()
|
||||
{
|
||||
var cancellationTokenSource = new CancellationTokenSource(1000);
|
||||
var tcpClient = new TcpClient();
|
||||
|
||||
try
|
||||
{
|
||||
_logger.LogDebug("tcp connecting {host} {port}", _hostName, 443);
|
||||
await tcpClient.ConnectAsync(_hostName, 443);
|
||||
await tcpClient.ConnectAsync(_hostName, 443, cancellationTokenSource.Token);
|
||||
_retry++;
|
||||
_logger.LogDebug("retry {retry}", _retry);
|
||||
if (tcpClient.Connected)
|
||||
@@ -44,7 +46,7 @@ public class HealthCheckService : IHealthCheckService
|
||||
else
|
||||
{
|
||||
_logger.LogDebug("wait next check in {waitTime}", _successRetry * 1000);
|
||||
await Task.Delay(_successRetry * 1000);
|
||||
await Task.Delay(_successRetry * 1000, cancellationTokenSource.Token);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -52,14 +54,14 @@ public class HealthCheckService : IHealthCheckService
|
||||
_successRetry = 0;
|
||||
_isOffline = true;
|
||||
_logger.LogDebug("current is {status}", "unavailable");
|
||||
await Task.Delay(500);
|
||||
await Task.Delay(500, cancellationTokenSource.Token);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError("fail cause :{reason}", ex.Message);
|
||||
_isOffline = true;
|
||||
await Task.Delay(5000);
|
||||
await Task.Delay(5000, cancellationTokenSource.Token);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user