overdue code cleanup (#1271)

This commit is contained in:
Jason Dove
2023-05-10 13:18:18 -05:00
committed by GitHub
parent 6142dcf153
commit 03df2a6c8a
259 changed files with 1357 additions and 1312 deletions
@@ -43,7 +43,7 @@ public class EndpointValidatorService : IHostedService
{
throw new NotSupportedException($"Invalid endpoint format: {urls}");
}
string baseUrl = Environment.GetEnvironmentVariable("ETV_BASE_URL");
_logger.LogInformation(
+10 -11
View File
@@ -15,8 +15,8 @@ namespace ErsatzTV.Services;
public class ScannerService : BackgroundService
{
private readonly ChannelReader<IScannerBackgroundServiceRequest> _channel;
private readonly IServiceScopeFactory _serviceScopeFactory;
private readonly ILogger<ScannerService> _logger;
private readonly IServiceScopeFactory _serviceScopeFactory;
public ScannerService(
ChannelReader<IScannerBackgroundServiceRequest> channel,
@@ -127,7 +127,7 @@ public class ScannerService : BackgroundService
entityLocker.UnlockLibrary(request.LibraryId);
}
}
private async Task SynchronizePlexLibrary(
ISynchronizePlexLibraryById request,
CancellationToken cancellationToken)
@@ -155,13 +155,13 @@ public class ScannerService : BackgroundService
error.Value);
}
});
if (entityLocker.IsLibraryLocked(request.PlexLibraryId))
{
entityLocker.UnlockLibrary(request.PlexLibraryId);
}
}
private async Task SynchronizeAdminUserId(
SynchronizeJellyfinAdminUserId request,
CancellationToken cancellationToken)
@@ -179,7 +179,7 @@ public class ScannerService : BackgroundService
request.JellyfinMediaSourceId,
error.Value));
}
private async Task SynchronizeLibraries(SynchronizeJellyfinLibraries request, CancellationToken cancellationToken)
{
using IServiceScope scope = _serviceScopeFactory.CreateScope();
@@ -195,7 +195,7 @@ public class ScannerService : BackgroundService
request.JellyfinMediaSourceId,
error.Value));
}
private async Task SynchronizeJellyfinLibrary(
ISynchronizeJellyfinLibraryById request,
CancellationToken cancellationToken)
@@ -229,7 +229,7 @@ public class ScannerService : BackgroundService
entityLocker.UnlockLibrary(request.JellyfinLibraryId);
}
}
private async Task SynchronizeLibraries(SynchronizeEmbyLibraries request, CancellationToken cancellationToken)
{
using IServiceScope scope = _serviceScopeFactory.CreateScope();
@@ -245,7 +245,7 @@ public class ScannerService : BackgroundService
request.EmbyMediaSourceId,
error.Value));
}
private async Task SynchronizeEmbyLibrary(ISynchronizeEmbyLibraryById request, CancellationToken cancellationToken)
{
using IServiceScope scope = _serviceScopeFactory.CreateScope();
@@ -271,7 +271,7 @@ public class ScannerService : BackgroundService
error.Value);
}
});
if (entityLocker.IsLibraryLocked(request.EmbyLibraryId))
{
entityLocker.UnlockLibrary(request.EmbyLibraryId);
@@ -300,11 +300,10 @@ public class ScannerService : BackgroundService
_logger.LogWarning("Unable to synchronize emby collections: {Error}", error.Value);
}
});
if (entityLocker.AreEmbyCollectionsLocked())
{
entityLocker.UnlockEmbyCollections();
}
}
}
+3 -3
View File
@@ -19,9 +19,9 @@ namespace ErsatzTV.Services;
public class SchedulerService : BackgroundService
{
private readonly ChannelWriter<IScannerBackgroundServiceRequest> _scannerWorkerChannel;
private readonly IEntityLocker _entityLocker;
private readonly ILogger<SchedulerService> _logger;
private readonly ChannelWriter<IScannerBackgroundServiceRequest> _scannerWorkerChannel;
private readonly IServiceScopeFactory _serviceScopeFactory;
private readonly ChannelWriter<IBackgroundServiceRequest> _workerChannel;
@@ -243,11 +243,11 @@ public class SchedulerService : BackgroundService
TvContext dbContext = scope.ServiceProvider.GetRequiredService<TvContext>();
var mediaSourceIds = new System.Collections.Generic.HashSet<int>();
foreach (EmbyLibrary library in dbContext.EmbyLibraries.Filter(l => l.ShouldSyncItems))
{
mediaSourceIds.Add(library.MediaSourceId);
if (_entityLocker.LockLibrary(library.Id))
{
await _scannerWorkerChannel.WriteAsync(