mirror of https://github.com/ErsatzTV/ErsatzTV.git
Browse Source
* don't search an empty search index * fix bug with flood filler prediction check * extract subtitles on primary worker threadpull/1108/head
10 changed files with 35 additions and 99 deletions
@ -1,5 +0,0 @@ |
|||||||
namespace ErsatzTV.Application; |
|
||||||
|
|
||||||
public interface ISubtitleWorkerRequest |
|
||||||
{ |
|
||||||
} |
|
||||||
@ -1,66 +0,0 @@ |
|||||||
using System.Threading.Channels; |
|
||||||
using Bugsnag; |
|
||||||
using ErsatzTV.Application; |
|
||||||
using ErsatzTV.Application.Subtitles; |
|
||||||
using MediatR; |
|
||||||
|
|
||||||
namespace ErsatzTV.Services; |
|
||||||
|
|
||||||
public class SubtitleWorkerService : BackgroundService |
|
||||||
{ |
|
||||||
private readonly ChannelReader<ISubtitleWorkerRequest> _channel; |
|
||||||
private readonly ILogger<SubtitleWorkerService> _logger; |
|
||||||
private readonly IServiceScopeFactory _serviceScopeFactory; |
|
||||||
|
|
||||||
public SubtitleWorkerService( |
|
||||||
ChannelReader<ISubtitleWorkerRequest> channel, |
|
||||||
IServiceScopeFactory serviceScopeFactory, |
|
||||||
ILogger<SubtitleWorkerService> logger) |
|
||||||
{ |
|
||||||
_channel = channel; |
|
||||||
_serviceScopeFactory = serviceScopeFactory; |
|
||||||
_logger = logger; |
|
||||||
} |
|
||||||
|
|
||||||
protected override async Task ExecuteAsync(CancellationToken cancellationToken) |
|
||||||
{ |
|
||||||
try |
|
||||||
{ |
|
||||||
_logger.LogInformation("Subtitle worker service started"); |
|
||||||
|
|
||||||
await foreach (ISubtitleWorkerRequest request in _channel.ReadAllAsync(cancellationToken)) |
|
||||||
{ |
|
||||||
using IServiceScope scope = _serviceScopeFactory.CreateScope(); |
|
||||||
|
|
||||||
try |
|
||||||
{ |
|
||||||
switch (request) |
|
||||||
{ |
|
||||||
case ExtractEmbeddedSubtitles extractEmbeddedSubtitles: |
|
||||||
IMediator mediator = scope.ServiceProvider.GetRequiredService<IMediator>(); |
|
||||||
await mediator.Send(extractEmbeddedSubtitles, cancellationToken); |
|
||||||
break; |
|
||||||
} |
|
||||||
} |
|
||||||
catch (Exception ex) |
|
||||||
{ |
|
||||||
_logger.LogWarning(ex, "Failed to handle subtitle worker request"); |
|
||||||
|
|
||||||
try |
|
||||||
{ |
|
||||||
IClient client = scope.ServiceProvider.GetRequiredService<IClient>(); |
|
||||||
client.Notify(ex); |
|
||||||
} |
|
||||||
catch (Exception) |
|
||||||
{ |
|
||||||
// do nothing
|
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
catch (Exception ex) when (ex is TaskCanceledException or OperationCanceledException) |
|
||||||
{ |
|
||||||
_logger.LogInformation("Subtitle worker service shutting down"); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
Loading…
Reference in new issue