Choropleth of the 80 Thurgau municipalities from the road vehicle stock dataset (djs-stv-17): vehicles per 1000 inhabitants by vehicle group or share of a car brand among passenger cars, with year controls and a municipality panel. Population comes from sk-stat-56, outlines from swisstopo swissBOUNDARIES3D. Also fixes the broken ENV line in the Dockerfile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.Vehicles;
|
|
|
|
public sealed class VehicleRefreshService(
|
|
VehicleRefresher refresher,
|
|
IOptions<VehicleOptions> options,
|
|
ILogger<VehicleRefreshService> logger) : BackgroundService
|
|
{
|
|
private static readonly TimeSpan CheckInterval = TimeSpan.FromMinutes(30);
|
|
|
|
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 vehicle 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, "Vehicle refresh failed");
|
|
}
|
|
|
|
await Task.Delay(CheckInterval, stoppingToken);
|
|
}
|
|
}
|
|
}
|