Initial QMAX production app
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
using Microsoft.Extensions.Options;
|
||||
using QMax.Api.Configuration;
|
||||
|
||||
namespace QMax.Api.Services;
|
||||
|
||||
public sealed class MaxSyncWorker(
|
||||
IOptions<QMaxOptions> options,
|
||||
MaxBridgeSyncService syncService,
|
||||
ILogger<MaxSyncWorker> logger) : BackgroundService
|
||||
{
|
||||
private readonly QMaxOptions _options = options.Value;
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
var delay = TimeSpan.FromSeconds(Math.Max(3, _options.MaxPollIntervalSeconds));
|
||||
using var timer = new PeriodicTimer(delay);
|
||||
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
await syncService.SyncOnceAsync(stoppingToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogWarning(ex, "QMAX background sync tick failed.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await timer.WaitForNextTickAsync(stoppingToken);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user