Moved notification back to DownloadChapterTask

temp: Dont wait for childTasks to finish to finish parent task
This commit is contained in:
glax 2023-07-02 23:06:24 +02:00
parent c97ff69148
commit f9a7828d02
2 changed files with 5 additions and 26 deletions

View File

@ -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}");
}

View File

@ -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;
}