Skip to content

Commit

Permalink
sync intervals
Browse files Browse the repository at this point in the history
  • Loading branch information
Svisstack committed Jun 14, 2024
1 parent c32f258 commit c1cbec7
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions data-api/csharp-ws/CoinAPI.WebSocket.Stats.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ private async Task PrintingTaskLoopAsync(CoinApiWsClient wsClient,
if (!wsClient.IsConnected)
{
Log.Warning("Websocket is not connected.");
await Task.Delay(1000);
await DelayToNextFullSecond();
continue;
}

Expand All @@ -311,7 +311,7 @@ private async Task PrintingTaskLoopAsync(CoinApiWsClient wsClient,

//TimeSpan totalCpuTimePrev = process.TotalProcessorTime;

await Task.Delay(1000);
await DelayToNextFullSecond();
(TimeSpan cpuWaiting, TimeSpan cpuParsing, TimeSpan cpuHandling) cpuUsage
= (wsClient.TotalWaitTime, wsClient.TotalParseTime, wsClient.TotalHandleTime);

Expand Down Expand Up @@ -360,6 +360,15 @@ private async Task PrintingTaskLoopAsync(CoinApiWsClient wsClient,

}
}

private static async Task DelayToNextFullSecond()
{
var now = DateTime.Now;
var nextFullSecond = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second).AddSeconds(1);
var delay = nextFullSecond - now;
await Task.Delay(delay);
}

static void AppConfigureServices(IServiceCollection services, IConfiguration configuration)
{
// Add configuration, logging, and IDataOutput implementations
Expand Down

0 comments on commit c1cbec7

Please sign in to comment.