From f9a7828d02427c27094a517875c8c752ecf04be8 Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 2 Jul 2023 23:06:24 +0200 Subject: [PATCH] Moved notification back to DownloadChapterTask temp: Dont wait for childTasks to finish to finish parent task --- Tranga/TrangaTask.cs | 28 ++--------------------- Tranga/TrangaTasks/DownloadChapterTask.cs | 3 +++ 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/Tranga/TrangaTask.cs b/Tranga/TrangaTask.cs index 4888044..6dbf0d1 100644 --- a/Tranga/TrangaTask.cs +++ b/Tranga/TrangaTask.cs @@ -77,34 +77,10 @@ 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); - - if((int)statusCode >= 200 && (int)statusCode < 300 && parentTask is null) - foreach(NotificationManager nm in taskManager.settings.notificationManagers) - switch (this.task) - { - case Task.MonitorPublication: - MonitorPublicationTask mpt = (MonitorPublicationTask)this; - int successfulCount = this.childTasks.Count(ct => ct.state is ExecutionState.Success); - if(successfulCount > 0) - nm.SendNotification("Downloaded new chapters", $"{mpt.publication.sortName}: {successfulCount} new chapters."); - break; - case Task.DownloadChapter: - DownloadChapterTask dct = (DownloadChapterTask)this; - nm.SendNotification("Chapter downloaded", $"{dct.publication.sortName} {dct.chapter.chapterNumber} {dct.chapter.name}"); - break; - } - - if ((int)statusCode >= 200 && (int)statusCode < 300) { this.lastExecuted = DateTime.Now; this.state = ExecutionState.Success; - }else if (statusCode is HttpStatusCode.NotFound) - { - this.state = ExecutionState.Waiting; - this.lastExecuted = DateTime.MaxValue; } else { @@ -112,8 +88,8 @@ public abstract class TrangaTask this.lastExecuted = DateTime.MaxValue; } - foreach (TrangaTask childTask in this.childTasks.Where(ct => ct is DownloadChapterTask).ToArray()) - taskManager.DeleteTask(childTask); + if (this is DownloadChapterTask) + taskManager.DeleteTask(this); logger?.WriteLine(this.GetType().ToString(), $"Finished Executing Task {this}"); } diff --git a/Tranga/TrangaTasks/DownloadChapterTask.cs b/Tranga/TrangaTasks/DownloadChapterTask.cs index 008026d..4aba6ab 100644 --- a/Tranga/TrangaTasks/DownloadChapterTask.cs +++ b/Tranga/TrangaTasks/DownloadChapterTask.cs @@ -27,6 +27,9 @@ public class DownloadChapterTask : TrangaTask Connector connector = taskManager.GetConnector(this.connectorName); connector.CopyCoverFromCacheToDownloadLocation(this.publication, taskManager.settings); HttpStatusCode downloadSuccess = connector.DownloadChapter(this.publication, this.chapter, this, cancellationToken); + if((int)downloadSuccess >= 200 && (int)downloadSuccess < 300) + foreach(NotificationManager nm in taskManager.settings.notificationManagers) + nm.SendNotification("Chapter downloaded", $"{this.publication.sortName} {this.chapter.chapterNumber} {this.chapter.name}"); return downloadSuccess; }