mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 12:02:35 +02:00
Added extra logging to update/ProcessProvider
This commit is contained in:
parent
50c4aa7557
commit
0884fa617a
@ -1,8 +1,11 @@
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Model;
|
||||
using NzbDrone.Test.Common;
|
||||
using NzbDrone.Test.Dummy;
|
||||
|
||||
@ -39,6 +42,8 @@ public void Kill_should_not_fail_on_invalid_process_is(int processId)
|
||||
public void GetById_should_return_null_if_process_doesnt_exist()
|
||||
{
|
||||
_processProvider.GetProcessById(1234567).Should().BeNull();
|
||||
|
||||
ExceptionVerification.ExcpectedWarns(1);
|
||||
}
|
||||
|
||||
[TestCase(0)]
|
||||
@ -47,6 +52,8 @@ public void GetById_should_return_null_if_process_doesnt_exist()
|
||||
public void GetProcessById_should_return_null_for_invalid_process(int processId)
|
||||
{
|
||||
_processProvider.GetProcessById(processId).Should().BeNull();
|
||||
|
||||
ExceptionVerification.ExcpectedWarns(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -77,5 +84,11 @@ public Process StartDummyProcess()
|
||||
return _processProvider.Start(startInfo);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ToString_on_new_processInfo()
|
||||
{
|
||||
Console.WriteLine(new ProcessInfo().ToString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,13 @@ namespace NzbDrone.Common.Model
|
||||
public class ProcessInfo
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public ProcessPriorityClass Priority { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string StartPath { get; set; }
|
||||
public ProcessPriorityClass Priority { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("{0}:{1} [{2}] [{3}]", Id, Name ?? "Unknown", StartPath ?? "Unknown", Priority);
|
||||
}
|
||||
}
|
||||
}
|
@ -19,7 +19,20 @@ public virtual ProcessInfo GetCurrentProcess()
|
||||
|
||||
public virtual ProcessInfo GetProcessById(int id)
|
||||
{
|
||||
return ConvertToProcessInfo(Process.GetProcesses().Where(p => p.Id == id).FirstOrDefault());
|
||||
Logger.Trace("Finding process with Id:{0}", id);
|
||||
|
||||
var processInfo = ConvertToProcessInfo(Process.GetProcesses().Where(p => p.Id == id).FirstOrDefault());
|
||||
|
||||
if (processInfo == null)
|
||||
{
|
||||
Logger.Warn("Unable to find process with ID {0}", id);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Trace("Found process {0}", processInfo.ToString());
|
||||
}
|
||||
|
||||
return processInfo;
|
||||
}
|
||||
|
||||
public virtual IEnumerable<ProcessInfo> GetProcessByName(string name)
|
||||
@ -84,7 +97,8 @@ private static ProcessInfo ConvertToProcessInfo(Process process)
|
||||
{
|
||||
Id = process.Id,
|
||||
Priority = process.PriorityClass,
|
||||
StartPath = process.MainModule.FileName
|
||||
StartPath = process.MainModule.FileName,
|
||||
Name = process.ProcessName
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ protected string VirtualPath
|
||||
[SetUp]
|
||||
public void TestBaseSetup()
|
||||
{
|
||||
if (Directory.Exists(TempFolder))
|
||||
if (Directory.Exists(TempFolder) && Directory.GetFiles(TempFolder, "*.*", SearchOption.AllDirectories).Any())
|
||||
{
|
||||
Directory.Delete(TempFolder, true);
|
||||
}
|
||||
|
@ -1,8 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
|
@ -84,21 +84,22 @@ public void Start(string[] args)
|
||||
VerfityArguments(args);
|
||||
int processId = ParseProcessId(args);
|
||||
|
||||
FileInfo exeFileInfo = new FileInfo(_processProvider.GetProcessById(processId).StartPath);
|
||||
string appPath = exeFileInfo.Directory.FullName;
|
||||
var exeFileInfo = new FileInfo(_processProvider.GetProcessById(processId).StartPath);
|
||||
string targetFolder = exeFileInfo.Directory.FullName;
|
||||
|
||||
logger.Info("Starting update process");
|
||||
_updateProvider.Start(appPath);
|
||||
logger.Info("Starting update process. Target Path:{0}", targetFolder);
|
||||
_updateProvider.Start(targetFolder);
|
||||
}
|
||||
|
||||
private int ParseProcessId(string[] args)
|
||||
{
|
||||
int id = 0;
|
||||
int id;
|
||||
if (!Int32.TryParse(args[0], out id) || id <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("Invalid process id: " + args[0]);
|
||||
}
|
||||
|
||||
logger.Debug("NzbDrone processId:{0}", id);
|
||||
return id;
|
||||
}
|
||||
|
||||
@ -106,6 +107,8 @@ private void VerfityArguments(string[] args)
|
||||
{
|
||||
if (args == null || args.Length != 2)
|
||||
throw new ArgumentException("Wrong number of parameters were passed in.");
|
||||
|
||||
logger.Debug("Arguments verified. [{0}] , [{1}]", args[0], args[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user