Improve TorBox status mapping to TorrentStatus and log any unmapped statuses for debugging.
This commit is contained in:
parent
40be170677
commit
f25cef711b
3 changed files with 51 additions and 1 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
public enum TorrentStatus
|
||||
{
|
||||
// Queued by RDTClient, not the provider.
|
||||
Queued = 0,
|
||||
|
||||
Processing = 1,
|
||||
|
|
|
|||
|
|
@ -478,4 +478,36 @@ public class TorBoxDebridClientTest
|
|||
Assert.Equal("https://real-usenet-link", result);
|
||||
usenetApiMock.Verify(m => m.RequestDownloadAsync(98765, 4321, false, It.IsAny<CancellationToken>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateData_LogsWarning_WhenTorBoxStatusIsUnmapped()
|
||||
{
|
||||
// Arrange
|
||||
var torrent = new Torrent
|
||||
{
|
||||
RdId = "test-rd-id",
|
||||
RdStatus = TorrentStatus.Downloading,
|
||||
RdName = "test-torrent"
|
||||
};
|
||||
var torrentClientTorrent = new DebridClientTorrent
|
||||
{
|
||||
Status = "some-unknown-status",
|
||||
Filename = "test-torrent"
|
||||
};
|
||||
|
||||
var clientMock = new Mock<TorBoxDebridClient>(_loggerMock.Object, _httpClientFactoryMock.Object, _fileFilterMock.Object);
|
||||
|
||||
// Act
|
||||
await clientMock.Object.UpdateData(torrent, torrentClientTorrent);
|
||||
|
||||
// Assert
|
||||
_loggerMock.Verify(
|
||||
x => x.Log(
|
||||
Microsoft.Extensions.Logging.LogLevel.Information,
|
||||
It.IsAny<EventId>(),
|
||||
It.Is<It.IsAnyType>((v, t) => v.ToString()!.Contains("unmapped status") && v.ToString()!.Contains("some-unknown-status")),
|
||||
It.IsAny<Exception>(),
|
||||
It.Is<Func<It.IsAnyType, Exception?, String>>((v, t) => true)),
|
||||
Times.Once);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -389,13 +389,17 @@ public class TorBoxDebridClient(ILogger<TorBoxDebridClient> logger, IHttpClientF
|
|||
}
|
||||
else
|
||||
{
|
||||
logger.LogTrace("Updating status for {TorrentName} from {OldStatus} to {NewStatus}", torrent.RdName, torrent.RdStatus, rdTorrent.Status);
|
||||
torrent.RdStatus = rdTorrent.Status switch
|
||||
{
|
||||
"allocating" => TorrentStatus.Processing,
|
||||
"queued" => TorrentStatus.Processing,
|
||||
"queuedDL" => TorrentStatus.Processing,
|
||||
"metaDL" => TorrentStatus.Processing,
|
||||
"checking" => TorrentStatus.Processing,
|
||||
"checkingResumeData" => TorrentStatus.Processing,
|
||||
"paused" => TorrentStatus.Downloading,
|
||||
"pausedDL" => TorrentStatus.Downloading,
|
||||
"stalledDL" => TorrentStatus.Downloading,
|
||||
"downloading" => TorrentStatus.Downloading,
|
||||
"completed" => TorrentStatus.Downloading,
|
||||
|
|
@ -404,8 +408,11 @@ public class TorBoxDebridClient(ILogger<TorBoxDebridClient> logger, IHttpClientF
|
|||
"stalled" => TorrentStatus.Downloading,
|
||||
"stalled (no seeds)" => TorrentStatus.Downloading,
|
||||
"processing" => TorrentStatus.Downloading,
|
||||
"checkingDL" => TorrentStatus.Downloading,
|
||||
"cached" => TorrentStatus.Finished,
|
||||
_ => TorrentStatus.Error
|
||||
"error" => TorrentStatus.Error,
|
||||
_ when rdTorrent.Status != null && rdTorrent.Status.StartsWith("failed") => TorrentStatus.Error,
|
||||
_ => LogUnmappedStatus(rdTorrent.Status, torrent)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -555,6 +562,16 @@ public class TorBoxDebridClient(ILogger<TorBoxDebridClient> logger, IHttpClientF
|
|||
}
|
||||
}
|
||||
|
||||
private TorrentStatus LogUnmappedStatus(String? status, Torrent torrent)
|
||||
{
|
||||
if (!String.IsNullOrWhiteSpace(status))
|
||||
{
|
||||
logger.LogInformation("TorBoxDebridClient encountered an unmapped status: {Status} for torrent {TorrentName}", status, torrent.RdName);
|
||||
}
|
||||
|
||||
return torrent.RdStatus ?? TorrentStatus.Processing;
|
||||
}
|
||||
|
||||
private void Log(String message, Torrent? torrent = null)
|
||||
{
|
||||
if (torrent != null)
|
||||
|
|
|
|||
Loading…
Reference in a new issue