- New Schaad.OpenData.Hydrology project: LindasHydroClient fetches the
current level, discharge, water temperature and danger level of nine
BAFU stations around Thurgau from LINDAS every 10 minutes
- LINDAS has no history, so the server keeps readings per day (60 days)
and fills gaps from the 7-day plot JSON of hydrodaten.admin.ch
- API: /api/hydrology/meta, /stations, /stations/{id}/history
- Combined map: "Gewässer (live)" layer with river circles (size by
discharge, colour by danger level or water temperature), lake level
badges, station panel with 7-day chart, overview and municipality
context entries
- Docs: docs/datasets/gewaesser.md, overview in docs/datasets.md,
CLAUDE.md; Docker and appsettings wiring
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claudio Schaad <c.schaad@pog.ch>
Co-committed-by: Claudio Schaad <c.schaad@pog.ch>
42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace Schaad.OpenData.Hydrology;
|
|
|
|
public sealed class HydrologyRefreshService(
|
|
HydrologyRefresher refresher,
|
|
IOptions<HydrologyOptions> options,
|
|
ILogger<HydrologyRefreshService> logger) : BackgroundService
|
|
{
|
|
private static readonly TimeSpan CheckInterval = TimeSpan.FromMinutes(1);
|
|
|
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
{
|
|
try
|
|
{
|
|
await refresher.LoadCacheAsync(stoppingToken);
|
|
}
|
|
catch (Exception exception) when (exception is not OperationCanceledException)
|
|
{
|
|
logger.LogError(exception, "Could not load the hydrology cache");
|
|
}
|
|
|
|
while (!stoppingToken.IsCancellationRequested)
|
|
{
|
|
try
|
|
{
|
|
if (refresher.IsRefreshDue(options.Value.RefreshInterval))
|
|
{
|
|
await refresher.RefreshAsync(stoppingToken);
|
|
}
|
|
}
|
|
catch (Exception exception) when (exception is not OperationCanceledException)
|
|
{
|
|
logger.LogError(exception, "Hydrology refresh failed");
|
|
}
|
|
|
|
await Task.Delay(CheckInterval, stoppingToken);
|
|
}
|
|
}
|
|
}
|