summaryrefslogtreecommitdiffstats
path: root/win
diff options
context:
space:
mode:
authorsr55 <[email protected]>2020-12-03 20:24:08 +0000
committersr55 <[email protected]>2020-12-03 20:24:08 +0000
commite0038b2e9008782ea2610dcf1de4e5ef5a727b58 (patch)
tree11f9c98b71e778e3ecf2093608f55f3af455293d /win
parent3b0bd7689579fb8012a3a6c00eae53243c61d8bd (diff)
WinGui: Improved reliablity of the queue service with multiple instances running. Note, there will now be up to a 3.5 second delay before starting each new job.
Diffstat (limited to 'win')
-rw-r--r--win/CS/HandBrake.Worker/Routing/ApiRouter.cs1
-rw-r--r--win/CS/HandBrakeWPF/Instance/RemoteInstance.cs21
-rw-r--r--win/CS/HandBrakeWPF/Services/Queue/QueueResourceService.cs2
-rw-r--r--win/CS/HandBrakeWPF/Services/Queue/QueueService.cs70
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs6
5 files changed, 61 insertions, 39 deletions
diff --git a/win/CS/HandBrake.Worker/Routing/ApiRouter.cs b/win/CS/HandBrake.Worker/Routing/ApiRouter.cs
index a3fdc6369..e1ea632a8 100644
--- a/win/CS/HandBrake.Worker/Routing/ApiRouter.cs
+++ b/win/CS/HandBrake.Worker/Routing/ApiRouter.cs
@@ -156,6 +156,7 @@ namespace HandBrake.Worker.Routing
if (!command.AllowDisconnectedWorker)
{
+ Console.WriteLine("Worker: Disconnected worker monitoring enabled!");
this.instanceWatcher = new InstanceWatcher(this);
this.instanceWatcher.Start(5000);
}
diff --git a/win/CS/HandBrakeWPF/Instance/RemoteInstance.cs b/win/CS/HandBrakeWPF/Instance/RemoteInstance.cs
index aefed4198..86af2aec9 100644
--- a/win/CS/HandBrakeWPF/Instance/RemoteInstance.cs
+++ b/win/CS/HandBrakeWPF/Instance/RemoteInstance.cs
@@ -63,17 +63,23 @@ namespace HandBrakeWPF.Instance
public async void PauseEncode()
{
- await this.MakeHttpGetRequest("PauseEncode");
- this.StopPollingProgress();
+ if (this.IsServerRunning())
+ {
+ await this.MakeHttpGetRequest("PauseEncode");
+ this.StopPollingProgress();
+ }
}
public async void ResumeEncode()
{
- await this.MakeHttpGetRequest("ResumeEncode");
- this.MonitorEncodeProgress();
+ if (this.IsServerRunning())
+ {
+ await this.MakeHttpGetRequest("ResumeEncode");
+ this.MonitorEncodeProgress();
+ }
}
- public void StartEncode(JsonEncodeObject jobToStart)
+ public async void StartEncode(JsonEncodeObject jobToStart)
{
if (this.IsServerRunning())
{
@@ -88,7 +94,10 @@ namespace HandBrakeWPF.Instance
public async void StopEncode()
{
- await this.MakeHttpGetRequest("StopEncode");
+ if (this.IsServerRunning())
+ {
+ await this.MakeHttpGetRequest("StopEncode");
+ }
}
public JsonState GetEncodeProgress()
diff --git a/win/CS/HandBrakeWPF/Services/Queue/QueueResourceService.cs b/win/CS/HandBrakeWPF/Services/Queue/QueueResourceService.cs
index 819a5ae87..6e7ff8037 100644
--- a/win/CS/HandBrakeWPF/Services/Queue/QueueResourceService.cs
+++ b/win/CS/HandBrakeWPF/Services/Queue/QueueResourceService.cs
@@ -65,7 +65,7 @@ namespace HandBrakeWPF.Services.Queue
this.totalNvidiaInstances = 3;
// VCE Support still TBD
- this.totalVceInstances = 1;
+ this.totalVceInstances = 3;
// Whether using hardware or not, some CPU is needed so don't allow more jobs than CPU.
if (this.maxAllowedInstances > Utilities.SystemInfo.GetCpuCoreCount)
diff --git a/win/CS/HandBrakeWPF/Services/Queue/QueueService.cs b/win/CS/HandBrakeWPF/Services/Queue/QueueService.cs
index 089072136..1a8802799 100644
--- a/win/CS/HandBrakeWPF/Services/Queue/QueueService.cs
+++ b/win/CS/HandBrakeWPF/Services/Queue/QueueService.cs
@@ -12,8 +12,10 @@ namespace HandBrakeWPF.Services.Queue
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+ using System.Diagnostics;
using System.IO;
using System.Linq;
+ using System.Timers;
using System.Windows;
using HandBrake.Interop.Interop.Json.Queue;
@@ -36,6 +38,8 @@ namespace HandBrakeWPF.Services.Queue
using Newtonsoft.Json;
+ using Ookii.Dialogs.Wpf;
+
using EncodeCompletedEventArgs = Encode.EventArgs.EncodeCompletedEventArgs;
using Execute = Caliburn.Micro.Execute;
using GeneralApplicationException = Exceptions.GeneralApplicationException;
@@ -68,6 +72,8 @@ namespace HandBrakeWPF.Services.Queue
private EncodeTaskFactory encodeTaskFactory;
+ private Timer queueTaskPoller;
+
public QueueService(IUserSettingService userSettingService, ILog logService, IErrorService errorService, ILogInstanceManager logInstanceManager, IPortService portService)
{
this.userSettingService = userSettingService;
@@ -124,13 +130,7 @@ namespace HandBrakeWPF.Services.Queue
public bool IsEncoding => this.activeJobs.Any(service => service.IsEncoding);
- public ObservableCollection<QueueTask> Queue
- {
- get
- {
- return this.queue;
- }
- }
+ public ObservableCollection<QueueTask> Queue => this.queue;
public void Add(QueueTask job)
{
@@ -138,11 +138,6 @@ namespace HandBrakeWPF.Services.Queue
{
this.queue.Add(job);
this.InvokeQueueChanged(EventArgs.Empty);
-
- if (this.IsEncoding)
- {
- this.ProcessNextJob();
- }
}
}
@@ -156,11 +151,6 @@ namespace HandBrakeWPF.Services.Queue
}
this.InvokeQueueChanged(EventArgs.Empty);
-
- if (this.IsEncoding)
- {
- this.ProcessNextJob();
- }
}
}
@@ -365,8 +355,7 @@ namespace HandBrakeWPF.Services.Queue
return logPaths;
}
-
-
+
public QueueTask GetNextJobForProcessing()
{
if (this.queue.Count > 0)
@@ -509,6 +498,9 @@ namespace HandBrakeWPF.Services.Queue
this.IsProcessing = false;
this.IsPaused = true;
+
+ this.StopJobPolling();
+
this.InvokeQueuePaused(EventArgs.Empty);
}
@@ -551,6 +543,8 @@ namespace HandBrakeWPF.Services.Queue
this.IsProcessing = false;
this.IsPaused = false;
+ this.StopJobPolling();
+
if (stopExistingJobs || this.activeJobs.Count == 0)
{
this.InvokeQueueChanged(EventArgs.Empty);
@@ -604,9 +598,31 @@ namespace HandBrakeWPF.Services.Queue
handler(this, e);
}
}
-
+
private void ProcessNextJob()
{
+ this.StopJobPolling();
+ this.CheckAndHandleWork(); // Kick the first job off right away.
+
+ this.queueTaskPoller = new Timer();
+
+ this.queueTaskPoller.Interval = this.allowedInstances > 1 ? 3500 : 1000;
+
+ this.queueTaskPoller.Elapsed += (o, e) => { CheckAndHandleWork(); };
+ this.queueTaskPoller.Start();
+ }
+
+ private void StopJobPolling()
+ {
+ if (this.queueTaskPoller != null)
+ {
+ this.queueTaskPoller.Stop();
+ this.queueTaskPoller = null;
+ }
+ }
+
+ private void CheckAndHandleWork()
+ {
if (!this.processIsolationEnabled)
{
this.allowedInstances = 1;
@@ -649,8 +665,6 @@ namespace HandBrakeWPF.Services.Queue
this.InvokeQueueChanged(EventArgs.Empty);
this.InvokeJobProcessingStarted(new QueueProgressEventArgs(job));
this.BackupQueue(string.Empty);
-
- this.ProcessNextJob();
}
else
{
@@ -658,6 +672,8 @@ namespace HandBrakeWPF.Services.Queue
if (!this.activeJobs.Any(a => a.IsEncoding))
{
+ this.StopJobPolling();
+
// Fire the event to tell connected services.
this.InvokeQueueCompleted(new QueueCompletedEventArgs(false));
}
@@ -676,15 +692,7 @@ namespace HandBrakeWPF.Services.Queue
this.activeJobs.Remove(e.Job);
this.OnEncodeCompleted(e.EncodeEventArgs);
- if (!this.IsPaused && this.IsProcessing)
- {
- this.ProcessNextJob();
- }
- else
- {
- this.InvokeQueueChanged(EventArgs.Empty);
- this.InvokeQueueCompleted(new QueueCompletedEventArgs(true));
- }
+ this.InvokeQueueChanged(EventArgs.Empty);
}
private void InvokeQueueCompleted(QueueCompletedEventArgs e)
diff --git a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs
index c1db4a5d7..acd3a2b0a 100644
--- a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs
@@ -964,7 +964,7 @@ namespace HandBrakeWPF.ViewModels
{
get
{
- return new BindingList<int> { 1, 2, 3, 4, 5, 6 };
+ return new BindingList<int> { 1, 2, 3, 4, 5, 6, 7, 8 };
}
}
@@ -1257,6 +1257,10 @@ namespace HandBrakeWPF.ViewModels
this.RemoteServiceEnabled = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.ProcessIsolationEnabled);
this.RemoteServicePort = userSettingService.GetUserSetting<int>(UserSettingConstants.ProcessIsolationPort);
this.SimultaneousEncodes = userSettingService.GetUserSetting<int>(UserSettingConstants.SimultaneousEncodes);
+ if (this.SimultaneousEncodes > 8)
+ {
+ this.SimultaneousEncodes = 8;
+ }
}
public void UpdateSettings()