mirror of
https://github.com/Radarr/Radarr
synced 2024-12-21 23:42:23 +00:00
Deprecate Sizeleft and Timeleft queue item properties
Rename SizeLeft and TimeLeft queue item properties (cherry picked from commit b51a49097941e5f306cae5785c63985b319784fd) Fixed: Error loading queue (cherry picked from commit f9606518eef78117f1e06a8bcc34af57ab0d2454)
This commit is contained in:
parent
617b9c5d35
commit
114d260f42
8 changed files with 126 additions and 21 deletions
|
@ -311,11 +311,11 @@ private Queue.Queue GetQueueItem(PendingRelease pendingRelease, Lazy<DateTime> n
|
|||
ect = ect.AddMinutes(_configService.RssSyncInterval);
|
||||
}
|
||||
|
||||
var timeleft = ect.Subtract(DateTime.UtcNow);
|
||||
var timeLeft = ect.Subtract(DateTime.UtcNow);
|
||||
|
||||
if (timeleft.TotalSeconds < 0)
|
||||
if (timeLeft.TotalSeconds < 0)
|
||||
{
|
||||
timeleft = TimeSpan.Zero;
|
||||
timeLeft = TimeSpan.Zero;
|
||||
}
|
||||
|
||||
string downloadClientName = null;
|
||||
|
@ -336,9 +336,9 @@ private Queue.Queue GetQueueItem(PendingRelease pendingRelease, Lazy<DateTime> n
|
|||
Languages = pendingRelease.RemoteMovie.Languages,
|
||||
Title = pendingRelease.Title,
|
||||
Size = pendingRelease.RemoteMovie.Release.Size,
|
||||
Sizeleft = pendingRelease.RemoteMovie.Release.Size,
|
||||
SizeLeft = pendingRelease.RemoteMovie.Release.Size,
|
||||
RemoteMovie = pendingRelease.RemoteMovie,
|
||||
Timeleft = timeleft,
|
||||
TimeLeft = timeLeft,
|
||||
EstimatedCompletionTime = ect,
|
||||
Added = pendingRelease.Added,
|
||||
Status = Enum.TryParse(pendingRelease.Reason.ToString(), out QueueStatus outValue) ? outValue : QueueStatus.Unknown,
|
||||
|
|
|
@ -17,8 +17,8 @@ public class Queue : ModelBase
|
|||
public QualityModel Quality { get; set; }
|
||||
public decimal Size { get; set; }
|
||||
public string Title { get; set; }
|
||||
public decimal Sizeleft { get; set; }
|
||||
public TimeSpan? Timeleft { get; set; }
|
||||
public decimal SizeLeft { get; set; }
|
||||
public TimeSpan? TimeLeft { get; set; }
|
||||
public DateTime? EstimatedCompletionTime { get; set; }
|
||||
public DateTime? Added { get; set; }
|
||||
public QueueStatus Status { get; set; }
|
||||
|
|
|
@ -62,8 +62,8 @@ private Queue MapMovie(TrackedDownload trackedDownload, Movie movie)
|
|||
Quality = trackedDownload.RemoteMovie?.ParsedMovieInfo.Quality ?? new QualityModel(Quality.Unknown),
|
||||
Title = trackedDownload.DownloadItem.Title,
|
||||
Size = trackedDownload.DownloadItem.TotalSize,
|
||||
Sizeleft = trackedDownload.DownloadItem.RemainingSize,
|
||||
Timeleft = trackedDownload.DownloadItem.RemainingTime,
|
||||
SizeLeft = trackedDownload.DownloadItem.RemainingSize,
|
||||
TimeLeft = trackedDownload.DownloadItem.RemainingTime,
|
||||
Status = Enum.TryParse(trackedDownload.DownloadItem.Status.ToString(), out QueueStatus outValue) ? outValue : QueueStatus.Unknown,
|
||||
TrackedDownloadStatus = trackedDownload.Status,
|
||||
TrackedDownloadState = trackedDownload.State,
|
||||
|
@ -82,9 +82,9 @@ private Queue MapMovie(TrackedDownload trackedDownload, Movie movie)
|
|||
|
||||
queue.Id = HashConverter.GetHashInt31($"trackedDownload-{trackedDownload.DownloadClient}-{trackedDownload.DownloadItem.DownloadId}");
|
||||
|
||||
if (queue.Timeleft.HasValue)
|
||||
if (queue.TimeLeft.HasValue)
|
||||
{
|
||||
queue.EstimatedCompletionTime = DateTime.UtcNow.Add(queue.Timeleft.Value);
|
||||
queue.EstimatedCompletionTime = DateTime.UtcNow.Add(queue.TimeLeft.Value);
|
||||
}
|
||||
|
||||
return queue;
|
||||
|
|
73
src/NzbDrone.Integration.Test/ApiTests/QueueFixture.cs
Normal file
73
src/NzbDrone.Integration.Test/ApiTests/QueueFixture.cs
Normal file
|
@ -0,0 +1,73 @@
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
using NzbDrone.Integration.Test.Client;
|
||||
using Radarr.Api.V3.Queue;
|
||||
using Radarr.Http;
|
||||
|
||||
namespace NzbDrone.Integration.Test.ApiTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class QueueFixture : IntegrationTest
|
||||
{
|
||||
private PagingResource<QueueResource> GetFirstPage()
|
||||
{
|
||||
var request = Queue.BuildRequest();
|
||||
request.AddParameter("includeUnknownMovieItems", true);
|
||||
|
||||
return Queue.Get<PagingResource<QueueResource>>(request);
|
||||
}
|
||||
|
||||
private void RefreshQueue()
|
||||
{
|
||||
var command = Commands.Post(new SimpleCommandResource { Name = "RefreshMonitoredDownloads" });
|
||||
|
||||
for (var i = 0; i < 30; i++)
|
||||
{
|
||||
var updatedCommand = Commands.Get(command.Id);
|
||||
|
||||
if (updatedCommand.Status == CommandStatus.Completed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Thread.Sleep(1000);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Order(0)]
|
||||
public void ensure_queue_is_empty_when_download_client_is_configured()
|
||||
{
|
||||
EnsureNoDownloadClient();
|
||||
EnsureDownloadClient();
|
||||
|
||||
var queue = GetFirstPage();
|
||||
|
||||
queue.TotalRecords.Should().Be(0);
|
||||
queue.Records.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Order(1)]
|
||||
public void ensure_queue_is_not_empty()
|
||||
{
|
||||
EnsureNoDownloadClient();
|
||||
|
||||
var client = EnsureDownloadClient();
|
||||
var directory = client.Fields.First(v => v.Name == "watchFolder").Value as string;
|
||||
|
||||
File.WriteAllText(Path.Combine(directory, "Movie.Title.2024.mkv"), "Test Download");
|
||||
RefreshQueue();
|
||||
|
||||
var queue = GetFirstPage();
|
||||
|
||||
queue.TotalRecords.Should().Be(1);
|
||||
queue.Records.Should().NotBeEmpty();
|
||||
}
|
||||
}
|
||||
}
|
13
src/NzbDrone.Integration.Test/Client/QueueClient.cs
Normal file
13
src/NzbDrone.Integration.Test/Client/QueueClient.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
using Radarr.Api.V3.Queue;
|
||||
using RestSharp;
|
||||
|
||||
namespace NzbDrone.Integration.Test.Client
|
||||
{
|
||||
public class QueueClient : ClientBase<QueueResource>
|
||||
{
|
||||
public QueueClient(IRestClient restClient, string apiKey)
|
||||
: base(restClient, apiKey)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -53,6 +53,7 @@ public abstract class IntegrationTestBase
|
|||
public ClientBase<TagResource> Tags;
|
||||
public ClientBase<MovieResource> WantedMissing;
|
||||
public ClientBase<MovieResource> WantedCutoffUnmet;
|
||||
public QueueClient Queue;
|
||||
|
||||
private List<SignalRMessage> _signalRReceived;
|
||||
|
||||
|
@ -115,6 +116,7 @@ protected virtual void InitRestClients()
|
|||
Tags = new ClientBase<TagResource>(RestClient, ApiKey);
|
||||
WantedMissing = new ClientBase<MovieResource>(RestClient, ApiKey, "wanted/missing");
|
||||
WantedCutoffUnmet = new ClientBase<MovieResource>(RestClient, ApiKey, "wanted/cutoff");
|
||||
Queue = new QueueClient(RestClient, ApiKey);
|
||||
}
|
||||
|
||||
[OneTimeTearDown]
|
||||
|
|
|
@ -214,8 +214,8 @@ public PagingResource<QueueResource> GetQueue([FromQuery] PagingRequestResource
|
|||
if (pagingSpec.SortKey == "timeleft")
|
||||
{
|
||||
ordered = ascending
|
||||
? fullQueue.OrderBy(q => q.Timeleft, new TimeleftComparer())
|
||||
: fullQueue.OrderByDescending(q => q.Timeleft, new TimeleftComparer());
|
||||
? fullQueue.OrderBy(q => q.TimeLeft, new TimeleftComparer())
|
||||
: fullQueue.OrderByDescending(q => q.TimeLeft, new TimeleftComparer());
|
||||
}
|
||||
else if (pagingSpec.SortKey == "estimatedCompletionTime")
|
||||
{
|
||||
|
@ -266,7 +266,7 @@ public PagingResource<QueueResource> GetQueue([FromQuery] PagingRequestResource
|
|||
ordered = ascending ? fullQueue.OrderBy(orderByFunc) : fullQueue.OrderByDescending(orderByFunc);
|
||||
}
|
||||
|
||||
ordered = ordered.ThenByDescending(q => q.Size == 0 ? 0 : 100 - (q.Sizeleft / q.Size * 100));
|
||||
ordered = ordered.ThenByDescending(q => q.Size == 0 ? 0 : 100 - (q.SizeLeft / q.Size * 100));
|
||||
|
||||
pagingSpec.Records = ordered.Skip((pagingSpec.Page - 1) * pagingSpec.PageSize).Take(pagingSpec.PageSize).ToList();
|
||||
pagingSpec.TotalRecords = fullQueue.Count;
|
||||
|
@ -300,9 +300,9 @@ public PagingResource<QueueResource> GetQueue([FromQuery] PagingRequestResource
|
|||
return q => q.Size;
|
||||
case "progress":
|
||||
// Avoid exploding if a download's size is 0
|
||||
return q => 100 - (q.Sizeleft / Math.Max(q.Size * 100, 1));
|
||||
return q => 100 - (q.SizeLeft / Math.Max(q.Size * 100, 1));
|
||||
default:
|
||||
return q => q.Timeleft;
|
||||
return q => q.TimeLeft;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,8 +22,11 @@ public class QueueResource : RestResource
|
|||
public int CustomFormatScore { get; set; }
|
||||
public decimal Size { get; set; }
|
||||
public string Title { get; set; }
|
||||
public decimal Sizeleft { get; set; }
|
||||
public TimeSpan? Timeleft { get; set; }
|
||||
|
||||
// Collides with existing properties due to case-insensitive deserialization
|
||||
// public decimal SizeLeft { get; set; }
|
||||
// public TimeSpan? TimeLeft { get; set; }
|
||||
|
||||
public DateTime? EstimatedCompletionTime { get; set; }
|
||||
public DateTime? Added { get; set; }
|
||||
public QueueStatus Status { get; set; }
|
||||
|
@ -37,6 +40,12 @@ public class QueueResource : RestResource
|
|||
public bool DownloadClientHasPostImportCategory { get; set; }
|
||||
public string Indexer { get; set; }
|
||||
public string OutputPath { get; set; }
|
||||
|
||||
[Obsolete("Will be replaced by SizeLeft")]
|
||||
public decimal Sizeleft { get; set; }
|
||||
|
||||
[Obsolete("Will be replaced by TimeLeft")]
|
||||
public TimeSpan? Timeleft { get; set; }
|
||||
}
|
||||
|
||||
public static class QueueResourceMapper
|
||||
|
@ -62,8 +71,11 @@ public static QueueResource ToResource(this NzbDrone.Core.Queue.Queue model, boo
|
|||
CustomFormatScore = customFormatScore,
|
||||
Size = model.Size,
|
||||
Title = model.Title,
|
||||
Sizeleft = model.Sizeleft,
|
||||
Timeleft = model.Timeleft,
|
||||
|
||||
// Collides with existing properties due to case-insensitive deserialization
|
||||
// SizeLeft = model.SizeLeft,
|
||||
// TimeLeft = model.TimeLeft,
|
||||
|
||||
EstimatedCompletionTime = model.EstimatedCompletionTime,
|
||||
Added = model.Added,
|
||||
Status = model.Status,
|
||||
|
@ -76,7 +88,12 @@ public static QueueResource ToResource(this NzbDrone.Core.Queue.Queue model, boo
|
|||
DownloadClient = model.DownloadClient,
|
||||
DownloadClientHasPostImportCategory = model.DownloadClientHasPostImportCategory,
|
||||
Indexer = model.Indexer,
|
||||
OutputPath = model.OutputPath
|
||||
OutputPath = model.OutputPath,
|
||||
|
||||
#pragma warning disable CS0618
|
||||
Sizeleft = model.SizeLeft,
|
||||
Timeleft = model.TimeLeft,
|
||||
#pragma warning restore CS0618
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue