Skip to content

Commit

Permalink
Use LongRunning task
Browse files Browse the repository at this point in the history
  • Loading branch information
agile.zhou committed May 26, 2024
1 parent 501240a commit 12ecf53
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/AgileConfig.Server.Apisite/Metrics/MeterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,34 +78,40 @@ public void Start()

private Task StartCheckAppCountAsync()
{
return Task.Run(async () =>
return Task.Factory.StartNew(async () =>
{
while (true)
{
_appCount = await _appService.CountEnabledAppsAsync();
try
{
_appCount = await _appService.CountEnabledAppsAsync();
_configCount = await _configService.CountEnabledConfigsAsync();
_configCount = await _configService.CountEnabledConfigsAsync();
var services = await _serviceInfoService.GetAllServiceInfoAsync();
_serviceCount = services.Count;
var services = await _serviceInfoService.GetAllServiceInfoAsync();
_serviceCount = services.Count;
var nodes = await _serverNodeService.GetAllNodesAsync();
_serverNodeCount = nodes.Count;
var nodes = await _serverNodeService.GetAllNodesAsync();
_serverNodeCount = nodes.Count;
var clientCount = 0;
foreach (var item in nodes)
{
if (item.Status == NodeStatus.Online)
var clientCount = 0;
foreach (var item in nodes)
{
var clientInfos = await _remoteServer.GetClientsReportAsync(item.Id.ToString());
clientCount += clientInfos.ClientCount;
if (item.Status == NodeStatus.Online)
{
var clientInfos = await _remoteServer.GetClientsReportAsync(item.Id.ToString());
clientCount += clientInfos.ClientCount;
}
}
_clientCount = clientCount;
}
catch
{
}
_clientCount = clientCount;
await Task.Delay(1000 * _checkInterval);
}
});
}, TaskCreationOptions.LongRunning);
}
}
}

0 comments on commit 12ecf53

Please sign in to comment.