Public Access
54 lines
1.7 KiB
C#
54 lines
1.7 KiB
C#
namespace MeetingAssistant.Recording;
|
|
|
|
public sealed class OfflineTranscriptionBacklogHostedService : BackgroundService
|
|
{
|
|
private static readonly TimeSpan RetryDelay = TimeSpan.FromMinutes(1);
|
|
|
|
private readonly OfflineTranscriptionBacklogProcessor processor;
|
|
private readonly ILogger<OfflineTranscriptionBacklogHostedService> logger;
|
|
|
|
public OfflineTranscriptionBacklogHostedService(
|
|
OfflineTranscriptionBacklogProcessor processor,
|
|
ILogger<OfflineTranscriptionBacklogHostedService> logger)
|
|
{
|
|
this.processor = processor;
|
|
this.logger = logger;
|
|
}
|
|
|
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
{
|
|
while (!stoppingToken.IsCancellationRequested)
|
|
{
|
|
try
|
|
{
|
|
var processed = await processor.ProcessPendingAsync(stoppingToken);
|
|
if (processed > 0)
|
|
{
|
|
logger.LogInformation(
|
|
"Processed {ProcessedCount} offline transcription backlog item(s)",
|
|
processed);
|
|
}
|
|
}
|
|
catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested)
|
|
{
|
|
return;
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
logger.LogWarning(
|
|
exception,
|
|
"Offline transcription backlog processing failed; it will be retried later");
|
|
}
|
|
|
|
try
|
|
{
|
|
await Task.Delay(RetryDelay, stoppingToken);
|
|
}
|
|
catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|