no dupplicate recordings
This commit is contained in:
parent
fb539d6a32
commit
0a2d6a558c
@ -34,6 +34,7 @@ public class RecordingService : IRecordingService, IDisposable
|
|||||||
private readonly ConcurrentDictionary<string, Process> _activeProcesses = new();
|
private readonly ConcurrentDictionary<string, Process> _activeProcesses = new();
|
||||||
private static readonly JsonSerializerOptions _jsonOptions = new() { WriteIndented = true };
|
private static readonly JsonSerializerOptions _jsonOptions = new() { WriteIndented = true };
|
||||||
private readonly SemaphoreSlim _persistLock = new(1, 1);
|
private readonly SemaphoreSlim _persistLock = new(1, 1);
|
||||||
|
private readonly SemaphoreSlim _processLock = new(1, 1);
|
||||||
private List<RecordingEntry> _recordings = new();
|
private List<RecordingEntry> _recordings = new();
|
||||||
private bool _loaded;
|
private bool _loaded;
|
||||||
private bool _disposed;
|
private bool _disposed;
|
||||||
@ -305,6 +306,25 @@ public class RecordingService : IRecordingService, IDisposable
|
|||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task ProcessRecordingsAsync(CancellationToken cancellationToken)
|
public async Task ProcessRecordingsAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
// Prevent overlapping scheduler runs from spawning duplicate ffmpeg processes
|
||||||
|
if (!await _processLock.WaitAsync(0).ConfigureAwait(false))
|
||||||
|
{
|
||||||
|
_logger.LogDebug("ProcessRecordingsAsync already running, skipping");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await ProcessRecordingsCoreAsync(cancellationToken).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_processLock.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ProcessRecordingsCoreAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
await LoadRecordingsAsync().ConfigureAwait(false);
|
await LoadRecordingsAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
@ -515,6 +535,7 @@ public class RecordingService : IRecordingService, IDisposable
|
|||||||
}
|
}
|
||||||
|
|
||||||
_persistLock.Dispose();
|
_persistLock.Dispose();
|
||||||
|
_processLock.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
_disposed = true;
|
_disposed = true;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user