Moved the websocket update process to its own background thread to improve UI update consistency.
This commit is contained in:
parent
781937dc8f
commit
a25cd62ab0
9 changed files with 69 additions and 41 deletions
|
|
@ -62,12 +62,13 @@ export class TorrentFileAvailability {
|
|||
}
|
||||
|
||||
export enum RealDebridStatus {
|
||||
NotYetAdded = -1,
|
||||
Processing = 0,
|
||||
WaitingForFileSelection = 1,
|
||||
Downloading = 2,
|
||||
Finished = 3,
|
||||
Uploading = 4,
|
||||
Queued = 0,
|
||||
|
||||
Processing = 1,
|
||||
WaitingForFileSelection = 2,
|
||||
Downloading = 3,
|
||||
Finished = 4,
|
||||
Uploading = 5,
|
||||
|
||||
Error = 99,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,8 +87,8 @@ export class TorrentStatusPipe implements PipeTransform {
|
|||
}
|
||||
|
||||
switch (torrent.rdStatus) {
|
||||
case RealDebridStatus.NotYetAdded:
|
||||
return "Not Yet Added to Provider"
|
||||
case RealDebridStatus.Queued:
|
||||
return 'Not Yet Added to Provider';
|
||||
case RealDebridStatus.Downloading:
|
||||
if (torrent.rdSeeders < 1) {
|
||||
return `Torrent stalled`;
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
public enum TorrentStatus
|
||||
{
|
||||
NotYetAdded = -1,
|
||||
Queued = 0,
|
||||
|
||||
Processing = 0,
|
||||
WaitingForFileSelection = 1,
|
||||
Downloading = 2,
|
||||
Finished = 3,
|
||||
Uploading = 4,
|
||||
Processing = 1,
|
||||
WaitingForFileSelection = 2,
|
||||
Downloading = 3,
|
||||
Finished = 4,
|
||||
Uploading = 5,
|
||||
|
||||
Error = 99
|
||||
}
|
||||
|
|
@ -52,7 +52,7 @@ public class TaskRunner(ILogger<TaskRunner> logger, IServiceProvider serviceProv
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"Unexpected error occurred in TorrentDownloadManager.Tick: {ex.Message}");
|
||||
logger.LogError(ex, $"Unexpected error occurred in TaskRunner: {ex.Message}");
|
||||
}
|
||||
|
||||
await Task.Delay(TimeSpan.FromSeconds(1), stoppingToken);
|
||||
|
|
|
|||
|
|
@ -12,8 +12,7 @@ public class UpdateChecker(ILogger<UpdateChecker> logger) : BackgroundService
|
|||
|
||||
public static Boolean? IsInsecure { get; private set; }
|
||||
|
||||
private static readonly List<String> KnownGhsaIds = [
|
||||
];
|
||||
private static readonly List<String> KnownGhsaIds = [];
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ public class WatchFolderChecker(ILogger<WatchFolderChecker> logger, IServiceProv
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"Unexpected error occurred in ProviderUpdater: {ex.Message}");
|
||||
logger.LogError(ex, $"Unexpected error occurred in WatchFolderChecker: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using RdtClient.Service.Services;
|
||||
|
||||
namespace RdtClient.Service.BackgroundServices;
|
||||
|
||||
public class WebsocketsUpdater(ILogger<WebsocketsUpdater> logger, IServiceProvider serviceProvider) : BackgroundService
|
||||
{
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
while (!Startup.Ready)
|
||||
{
|
||||
await Task.Delay(1000, stoppingToken);
|
||||
}
|
||||
|
||||
var remoteService = serviceProvider.GetRequiredService<RemoteService>();
|
||||
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
await remoteService.Update();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"Unexpected error occurred in WebsocketsUpdater: {ex.Message}");
|
||||
}
|
||||
|
||||
await Task.Delay(TimeSpan.FromSeconds(1), stoppingToken);
|
||||
}
|
||||
|
||||
logger.LogInformation("WebsocketsUpdater stopped.");
|
||||
}
|
||||
}
|
||||
|
|
@ -11,7 +11,7 @@ using System.Text.Json;
|
|||
|
||||
namespace RdtClient.Service.Services;
|
||||
|
||||
public class TorrentRunner(ILogger<TorrentRunner> logger, Torrents torrents, Downloads downloads, RemoteService remoteService)
|
||||
public class TorrentRunner(ILogger<TorrentRunner> logger, Torrents torrents, Downloads downloads)
|
||||
{
|
||||
public static readonly ConcurrentDictionary<Guid, DownloadClient> ActiveDownloadClients = new();
|
||||
public static readonly ConcurrentDictionary<Guid, UnpackClient> ActiveUnpackClients = new();
|
||||
|
|
@ -315,12 +315,12 @@ public class TorrentRunner(ILogger<TorrentRunner> logger, Torrents torrents, Dow
|
|||
}
|
||||
|
||||
// Process torrents in DebridQueue
|
||||
var torrentsToAddToProvider = allTorrents.Where(m => m.RdId == null && m.RdAdded == null && m.FileOrMagnet != null && m.RdStatus == TorrentStatus.NotYetAdded)
|
||||
var torrentsToAddToProvider = allTorrents.Where(m => m.RdId == null && m.RdAdded == null && m.FileOrMagnet != null && m.RdStatus == TorrentStatus.Queued)
|
||||
.ToList();
|
||||
|
||||
if (torrentsToAddToProvider.Count != 0)
|
||||
{
|
||||
var downloadingTorrentsCount = allTorrents.Count(m => m.RdStatus is not (TorrentStatus.NotYetAdded or TorrentStatus.Finished or TorrentStatus.Error));
|
||||
var downloadingTorrentsCount = allTorrents.Count(m => m.RdStatus is not (TorrentStatus.Queued or TorrentStatus.Finished or TorrentStatus.Error));
|
||||
|
||||
var maxParallelDownloads = Settings.Get.Provider.MaxParallelDownloads;
|
||||
|
||||
|
|
@ -659,8 +659,6 @@ public class TorrentRunner(ILogger<TorrentRunner> logger, Torrents torrents, Dow
|
|||
}
|
||||
}
|
||||
|
||||
await remoteService.Update();
|
||||
|
||||
sw.Stop();
|
||||
|
||||
if (sw.ElapsedMilliseconds > 1000)
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ public class Torrents(
|
|||
throw new($"{ex.Message}, trying to parse {magnetLink}");
|
||||
}
|
||||
|
||||
torrent.RdStatus = TorrentStatus.NotYetAdded;
|
||||
torrent.RdStatus = TorrentStatus.Queued;
|
||||
torrent.RdName = magnet.Name;
|
||||
|
||||
var hash = magnet.InfoHashes.V1OrV2.ToHex();
|
||||
|
|
@ -151,7 +151,7 @@ public class Torrents(
|
|||
throw new($"{ex.Message}, trying to parse {fileAsBase64}");
|
||||
}
|
||||
|
||||
torrent.RdStatus = TorrentStatus.NotYetAdded;
|
||||
torrent.RdStatus = TorrentStatus.Queued;
|
||||
torrent.RdName = monoTorrent.Name;
|
||||
|
||||
var hash = monoTorrent.InfoHashes.V1OrV2.ToHex();
|
||||
|
|
@ -178,18 +178,13 @@ public class Torrents(
|
|||
|
||||
var copyFileName = Path.Combine(Settings.Get.General.CopyAddedTorrents, FileHelper.RemoveInvalidFileNameChars(torrentName));
|
||||
|
||||
switch (fileOrMagnet)
|
||||
copyFileName = fileOrMagnet switch
|
||||
{
|
||||
case String:
|
||||
copyFileName = $"{copyFileName}.magnet";
|
||||
break;
|
||||
case Byte[]:
|
||||
copyFileName = $"{copyFileName}.torrent";
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Unexpected type for fileOrMagnet");
|
||||
}
|
||||
|
||||
String => $"{copyFileName}.magnet",
|
||||
Byte[] => $"{copyFileName}.torrent",
|
||||
_ => throw new ArgumentException("Unexpected type for fileOrMagnet")
|
||||
};
|
||||
|
||||
if (File.Exists(copyFileName))
|
||||
{
|
||||
File.Delete(copyFileName);
|
||||
|
|
@ -743,11 +738,11 @@ public class Torrents(
|
|||
}
|
||||
|
||||
var newTorrent = await torrentData.Add(null,
|
||||
infoHash,
|
||||
fileOrMagnetContents,
|
||||
isFile,
|
||||
torrent.DownloadClient,
|
||||
torrent);
|
||||
infoHash,
|
||||
fileOrMagnetContents,
|
||||
isFile,
|
||||
torrent.DownloadClient,
|
||||
torrent);
|
||||
|
||||
return newTorrent;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue