From 8737617e5ffdb4ef4af3064fd8e506be0e64755b Mon Sep 17 00:00:00 2001 From: glax Date: Wed, 21 Jun 2023 16:53:41 +0200 Subject: [PATCH] Fix deletion of successful child tasks --- Tranga/TaskManager.cs | 16 +++++----------- Tranga/TrangaTask.cs | 2 ++ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Tranga/TaskManager.cs b/Tranga/TaskManager.cs index 0795f0f..5f32425 100644 --- a/Tranga/TaskManager.cs +++ b/Tranga/TaskManager.cs @@ -81,23 +81,15 @@ public class TaskManager break; } } - - TrangaTask[] failedDownloadChapterTasks = _allTasks.Where(taskQuery => - taskQuery.state is TrangaTask.ExecutionState.Failed && taskQuery is DownloadChapterTask).ToArray(); - foreach (TrangaTask failedDownloadChapterTask in failedDownloadChapterTasks) + + foreach (TrangaTask failedDownloadChapterTask in _allTasks.Where(taskQuery => + taskQuery.state is TrangaTask.ExecutionState.Failed && taskQuery is DownloadChapterTask).ToArray()) { DeleteTask(failedDownloadChapterTask); TrangaTask newTask = failedDownloadChapterTask.Clone(); failedDownloadChapterTask.parentTask?.AddChildTask(newTask); AddTask(newTask); } - - TrangaTask[] successfulDownloadChapterTasks = _allTasks.Where(taskQuery => - taskQuery.state is TrangaTask.ExecutionState.Success && taskQuery is DownloadChapterTask).ToArray(); - foreach(TrangaTask successfulDownloadChapterTask in successfulDownloadChapterTasks) - { - DeleteTask(successfulDownloadChapterTask); - } if(waitingTasksCount != _allTasks.Count(task => task.state is TrangaTask.ExecutionState.Waiting)) ExportDataAndSettings(); @@ -166,6 +158,8 @@ public class TaskManager _runningDownloadChapterTasks[cRemoveTask].Cancel(); _runningDownloadChapterTasks.Remove(cRemoveTask); } + foreach(TrangaTask childTask in removeTask.childTasks) + DeleteTask(childTask); } public IEnumerable GetTasksMatching(TrangaTask.Task taskType, string? connectorName = null, string? searchString = null, string? internalId = null, string? chapterSortNumber = null) diff --git a/Tranga/TrangaTask.cs b/Tranga/TrangaTask.cs index c418baf..0f01fa8 100644 --- a/Tranga/TrangaTask.cs +++ b/Tranga/TrangaTask.cs @@ -75,6 +75,8 @@ public abstract class TrangaTask HttpStatusCode statusCode = ExecuteTask(taskManager, logger, cancellationToken); while(childTasks.Any(ct => ct.state is ExecutionState.Enqueued or ExecutionState.Running)) Thread.Sleep(1000); + foreach(TrangaTask childTask in this.childTasks.ToArray()) + taskManager.DeleteTask(childTask); if ((int)statusCode >= 200 && (int)statusCode < 300) { this.lastExecuted = DateTime.Now;