Skip to content

Commit

Permalink
Log when cancellation was requested
Browse files Browse the repository at this point in the history
  • Loading branch information
awaescher authored Jun 19, 2024
1 parent 060af42 commit 1866d4e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion MaxPower/HostedServices/ExporterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ protected override async Task ExecuteAsync(CancellationToken cancellationToken)
Logger.LogInformation("Entering sleep state for {pollinterval} seconds.", MaxSettings.PollIntervalSeconds);
await Task.Delay(TimeSpan.FromSeconds(MaxSettings.PollIntervalSeconds), cancellationToken);
}

if (cancellationToken.IsCancellationRequested)
Logger.LogInformation("Cancellation requested, leaving loop ...");
}

private async Task ProcessInverter(InverterConfiguration inverter, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
{
Logger.LogInformation("Cancellation requested, skipping inverter {inverterId} ...", inverter.Id);
return;
}

// add an additional (generous) timeout to prevent the system from hanging if the socket conection hangs.
// seems to happen sometimes after some hours of working perfectly ...
Expand Down Expand Up @@ -68,4 +74,4 @@ private async Task ProcessInverter(InverterConfiguration inverter, CancellationT
_energyTotal.WithLabels(labels).Set(data?.EnergyTotal ?? 0);
}
}
}
}

0 comments on commit 1866d4e

Please sign in to comment.