Remove use of ProcessFactory, as well as arbitrary timeout in AttachmentExtractor.
This commit is contained in:
parent
380d023351
commit
79858eb26c
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
@ -31,7 +32,6 @@ namespace MediaBrowser.MediaEncoding.Attachments
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
private readonly IMediaEncoder _mediaEncoder;
|
private readonly IMediaEncoder _mediaEncoder;
|
||||||
private readonly IMediaSourceManager _mediaSourceManager;
|
private readonly IMediaSourceManager _mediaSourceManager;
|
||||||
private readonly IProcessFactory _processFactory;
|
|
||||||
|
|
||||||
public AttachmentExtractor(
|
public AttachmentExtractor(
|
||||||
ILibraryManager libraryManager,
|
ILibraryManager libraryManager,
|
||||||
|
@ -39,8 +39,7 @@ namespace MediaBrowser.MediaEncoding.Attachments
|
||||||
IApplicationPaths appPaths,
|
IApplicationPaths appPaths,
|
||||||
IFileSystem fileSystem,
|
IFileSystem fileSystem,
|
||||||
IMediaEncoder mediaEncoder,
|
IMediaEncoder mediaEncoder,
|
||||||
IMediaSourceManager mediaSourceManager,
|
IMediaSourceManager mediaSourceManager)
|
||||||
IProcessFactory processFactory)
|
|
||||||
{
|
{
|
||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
@ -48,7 +47,6 @@ namespace MediaBrowser.MediaEncoding.Attachments
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
_mediaEncoder = mediaEncoder;
|
_mediaEncoder = mediaEncoder;
|
||||||
_mediaSourceManager = mediaSourceManager;
|
_mediaSourceManager = mediaSourceManager;
|
||||||
_processFactory = processFactory;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private string AttachmentCachePath => Path.Combine(_appPaths.DataPath, "attachments");
|
private string AttachmentCachePath => Path.Combine(_appPaths.DataPath, "attachments");
|
||||||
|
@ -167,16 +165,19 @@ namespace MediaBrowser.MediaEncoding.Attachments
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
|
Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
|
||||||
|
|
||||||
var processArgs = string.Format("-dump_attachment:{1} {2} -i {0} -t 0 -f null null", inputPath, attachmentStreamIndex, outputPath);
|
var processArgs = string.Format("-dump_attachment:{1} {2} -i {0} -t 0 -f null null", inputPath, attachmentStreamIndex, outputPath);
|
||||||
var process = _processFactory.Create(new ProcessOptions
|
var startInfo = new ProcessStartInfo
|
||||||
{
|
{
|
||||||
CreateNoWindow = true,
|
|
||||||
UseShellExecute = false,
|
|
||||||
EnableRaisingEvents = true,
|
|
||||||
FileName = _mediaEncoder.EncoderPath,
|
|
||||||
Arguments = processArgs,
|
Arguments = processArgs,
|
||||||
IsHidden = true,
|
FileName = _mediaEncoder.EncoderPath,
|
||||||
|
UseShellExecute = false,
|
||||||
|
CreateNoWindow = true,
|
||||||
|
WindowStyle = ProcessWindowStyle.Hidden,
|
||||||
ErrorDialog = false
|
ErrorDialog = false
|
||||||
});
|
};
|
||||||
|
var process = new Process
|
||||||
|
{
|
||||||
|
StartInfo = startInfo
|
||||||
|
};
|
||||||
|
|
||||||
_logger.LogInformation("{File} {Arguments}", process.StartInfo.FileName, process.StartInfo.Arguments);
|
_logger.LogInformation("{File} {Arguments}", process.StartInfo.FileName, process.StartInfo.Arguments);
|
||||||
|
|
||||||
|
@ -191,7 +192,12 @@ namespace MediaBrowser.MediaEncoding.Attachments
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
var ranToCompletion = await process.WaitForExitAsync(300000).ConfigureAwait(false);
|
var processTcs = new TaskCompletionSource<bool>();
|
||||||
|
process.EnableRaisingEvents = true;
|
||||||
|
process.Exited += (sender, args) => processTcs.TrySetResult(true);
|
||||||
|
var unregister = cancellationToken.Register(() => processTcs.TrySetResult(process.HasExited));
|
||||||
|
var ranToCompletion = await processTcs.Task.ConfigureAwait(false);
|
||||||
|
unregister.Dispose();
|
||||||
|
|
||||||
if (!ranToCompletion)
|
if (!ranToCompletion)
|
||||||
{
|
{
|
||||||
|
@ -205,7 +211,6 @@ namespace MediaBrowser.MediaEncoding.Attachments
|
||||||
_logger.LogError(ex, "Error killing attachment extraction process");
|
_logger.LogError(ex, "Error killing attachment extraction process");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var exitCode = ranToCompletion ? process.ExitCode : -1;
|
var exitCode = ranToCompletion ? process.ExitCode : -1;
|
||||||
|
|
||||||
process.Dispose();
|
process.Dispose();
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<packages>
|
|
||||||
</packages>
|
|
Loading…
Reference in New Issue
Block a user