Removed obsolete torrent runner code, fixed queuing issue.

This commit is contained in:
Roger Far 2021-10-27 21:47:22 -06:00
parent 5d58bc9082
commit 5fa5f416c7
5 changed files with 23 additions and 108 deletions

View file

@ -22,7 +22,8 @@ export class TorrentStatusPipe implements PipeTransform {
return 'Finished';
}
const downloading = torrent.downloads.where((m) => m.downloadStarted && !m.downloadFinished);
const downloading = torrent.downloads.where((m) => m.downloadStarted && !m.downloadFinished && m.bytesDone > 0);
const downloaded = torrent.downloads.where((m) => m.downloadFinished != null);
if (downloading.length > 0) {
const bytesDone = downloading.sum((m) => m.bytesDone);
@ -33,17 +34,19 @@ export class TorrentStatusPipe implements PipeTransform {
progress = 0;
}
let allSpeeds = downloading.sum((m) => m.speed) / downloading.length;
let allSpeeds = downloading.sum((m) => m.speed);
let speed: string | string[] = '0';
if (allSpeeds > 0) {
speed = this.pipe.transform(allSpeeds, 'filesize');
return `Downloading file ${downloading.length}/${torrent.downloads.length} (${progress.toFixed(2)}% - ${speed}/s)`;
}
speed = this.pipe.transform(allSpeeds, 'filesize');
return `Downloading file ${downloading.length + downloaded.length}/${
torrent.downloads.length
} (${progress.toFixed(2)}% - ${speed}/s)`;
}
const unpacking = torrent.downloads.where((m) => m.unpackingStarted && !m.unpackingFinished);
const unpacking = torrent.downloads.where((m) => m.unpackingStarted && !m.unpackingFinished && m.bytesDone > 0);
const unpacked = torrent.downloads.where((m) => m.unpackingFinished != null);
if (unpacking.length > 0) {
const bytesDone = unpacking.sum((m) => m.bytesDone);
@ -54,11 +57,9 @@ export class TorrentStatusPipe implements PipeTransform {
progress = 0;
}
let allSpeeds = unpacking.sum((m) => m.speed) / unpacking.length;
if (allSpeeds > 0) {
return `Extracting file ${unpacking.length}/${torrent.downloads.length} (${progress.toFixed(2)}%)`;
}
return `Extracting file ${unpacking.length + unpacked.length}/${torrent.downloads.length} (${progress.toFixed(
2
)}%)`;
}
const queuedForUnpacking = torrent.downloads.where((m) => m.unpackingQueued && !m.unpackingStarted);
@ -73,14 +74,10 @@ export class TorrentStatusPipe implements PipeTransform {
return `Queued for downloading`;
}
const unpacked = torrent.downloads.where((m) => m.unpackingFinished != null);
if (unpacked.length > 0) {
return `Files unpacked`;
}
const downloaded = torrent.downloads.where((m) => m.downloadFinished != null);
if (downloaded.length > 0) {
return `Files downloaded to host`;
}

View file

@ -242,40 +242,6 @@ namespace RdtClient.Data.Data
await TorrentData.VoidCache();
}
public async Task Download(Guid downloadId)
{
var dbDownload = await _dataContext.Downloads
.FirstOrDefaultAsync(m => m.DownloadId == downloadId);
dbDownload.DownloadStarted = null;
dbDownload.DownloadFinished = null;
dbDownload.UnpackingQueued = null;
dbDownload.UnpackingStarted = null;
dbDownload.UnpackingFinished = null;
dbDownload.Completed = null;
dbDownload.Error = null;
await _dataContext.SaveChangesAsync();
await TorrentData.VoidCache();
}
public async Task Unpack(Guid downloadId)
{
var dbDownload = await _dataContext.Downloads
.FirstOrDefaultAsync(m => m.DownloadId == downloadId);
dbDownload.UnpackingQueued = DateTimeOffset.UtcNow;
dbDownload.UnpackingStarted = null;
dbDownload.UnpackingFinished = null;
dbDownload.Completed = null;
dbDownload.Error = null;
await _dataContext.SaveChangesAsync();
await TorrentData.VoidCache();
}
public async Task Reset(Guid downloadId)
{
var dbDownload = await _dataContext.Downloads

View file

@ -46,12 +46,15 @@ namespace RdtClient.Service.Services.Downloaders
var fileName = Path.GetFileName(_filePath);
_logger.Debug($"Starting download of {_uri}, writing to path: {path}, fileName: {fileName}");
var isAlreadyAdded = await CheckIfAdded();
if (isAlreadyAdded)
if (String.IsNullOrWhiteSpace(_gid))
{
throw new Exception($"The download link {_uri} has already been added to Aria2");
var isAlreadyAdded = await CheckIfAdded();
if (isAlreadyAdded)
{
throw new Exception($"The download link {_uri} has already been added to Aria2");
}
}
var retryCount = 0;

View file

@ -89,17 +89,7 @@ namespace RdtClient.Service.Services
{
await _downloadData.DeleteForTorrent(torrentId);
}
public async Task UpdateDownload(Guid downloadId)
{
await _downloadData.Download(downloadId);
}
public async Task UpdateUnpack(Guid downloadId)
{
await _downloadData.Unpack(downloadId);
}
public async Task Reset(Guid downloadId)
{
await _downloadData.Reset(downloadId);

View file

@ -179,7 +179,7 @@ namespace RdtClient.Service.Services
Log($"Retrying download", download, download.Torrent);
await _downloads.UpdateRetryCount(downloadId, download.RetryCount + 1);
await _downloads.UpdateDownload(downloadId);
await _downloads.Reset(downloadId);
}
else if (download.Torrent.RetryCount < TorrentRetryCount)
{
@ -549,47 +549,6 @@ namespace RdtClient.Service.Services
await _torrents.CheckForLinks(torrent.TorrentId);
}
// If the torrent has any files that need starting to be downloaded, download them.
var downloadsPending = torrent.Downloads
.Where(m => m.Completed == null &&
m.DownloadStarted == null &&
m.DownloadFinished == null &&
m.Error == null)
.OrderBy(m => m.Added)
.ToList();
if (downloadsPending.Count > 0)
{
Log($"Found {downloadsPending.Count} downloads pending", torrent);
foreach (var download in downloadsPending)
{
Log($"Marking to download", download, torrent);
await _downloads.UpdateDownload(download.DownloadId);
}
}
// If all files are finished downloading, move to the unpacking step.
var unpackingPending = torrent.Downloads
.Where(m => m.Completed == null &&
m.DownloadFinished != null &&
m.UnpackingStarted == null &&
m.UnpackingFinished == null)
.ToList();
if (unpackingPending.Count > 0)
{
Log($"Found {unpackingPending.Count} unpacks pending", torrent);
foreach (var download in unpackingPending)
{
Log($"Marking to unpack", download, torrent);
await _downloads.UpdateUnpack(download.DownloadId);
}
}
}
// Check if torrent is complete
@ -597,7 +556,7 @@ namespace RdtClient.Service.Services
{
var allComplete = torrent.Downloads.Count(m => m.Completed != null);
if (allComplete > 0)
if (allComplete == torrent.Downloads.Count)
{
Log($"All downloads complete, marking torrent as complete", torrent);