Order of tasks closes #15

Also API /Queue/Get orders in order of nextExecution
This commit is contained in:
glax 2023-06-10 00:45:46 +02:00
parent 8b916eb854
commit 234735a562
4 changed files with 26 additions and 11 deletions

View File

@ -196,7 +196,7 @@ app.MapGet("/Tasks/GetRunningTasks",
() => taskManager.GetAllTasks().Where(task => task.state is TrangaTask.ExecutionState.Running));
app.MapGet("/Queue/GetList",
() => taskManager.GetAllTasks().Where(task => task.state is TrangaTask.ExecutionState.Enqueued));
() => taskManager.GetAllTasks().Where(task => task.state is TrangaTask.ExecutionState.Enqueued).OrderBy(task => task.nextExecution));
app.MapPost("/Queue/Enqueue", (string taskType, string? connectorName, string? publicationId) =>
{

View File

@ -1,4 +1,5 @@
using System.Net;
using System.Globalization;
using System.Net;
using System.Text.RegularExpressions;
using HtmlAgilityPack;
using Logging;
@ -132,11 +133,18 @@ public class Manganato : Connector
downloadClient.MakeRequest(requestUrl, (byte)1);
if (requestResult.statusCode != HttpStatusCode.OK)
return Array.Empty<Chapter>();
return ParseChaptersFromHtml(requestResult.result);
//Return Chapters ordered by Chapter-Number
NumberFormatInfo chapterNumberFormatInfo = new()
{
NumberDecimalSeparator = "."
};
List<Chapter> chapters = ParseChaptersFromHtml(requestResult.result);
logger?.WriteLine(this.GetType().ToString(), $"Done getting Chapters for {publication.internalId}");
return chapters.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray();
}
private Chapter[] ParseChaptersFromHtml(Stream html)
private List<Chapter> ParseChaptersFromHtml(Stream html)
{
StreamReader reader = new (html);
string htmlString = reader.ReadToEnd();
@ -158,7 +166,7 @@ public class Manganato : Connector
ret.Add(new Chapter(chapterName, volumeNumber, chapterNumber, url));
}
ret.Reverse();
return ret.ToArray();
return ret;
}
public override void DownloadChapter(Publication publication, Chapter chapter, DownloadChapterTask parentTask)

View File

@ -1,4 +1,5 @@
using System.Net;
using System.Globalization;
using System.Net;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using HtmlAgilityPack;
@ -200,8 +201,13 @@ public class Mangasee : Connector
ret.Add(new Chapter("", volumeNumber, chapterNumber, url));
}
ret.Reverse();
return ret.ToArray();
//Return Chapters ordered by Chapter-Number
NumberFormatInfo chapterNumberFormatInfo = new()
{
NumberDecimalSeparator = "."
};
logger?.WriteLine(this.GetType().ToString(), $"Done getting Chapters for {publication.internalId}");
return ret.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray();
}
public override void DownloadChapter(Publication publication, Chapter chapter, DownloadChapterTask parentTask)

View File

@ -89,8 +89,9 @@ public class TaskManager
while (_continueRunning)
{
TrangaTask[] tmp = _allTasks.Where(taskQuery =>
taskQuery.nextExecution < DateTime.Now &&
taskQuery.state is TrangaTask.ExecutionState.Waiting or TrangaTask.ExecutionState.Enqueued).ToArray();
taskQuery.nextExecution < DateTime.Now &&
taskQuery.state is TrangaTask.ExecutionState.Waiting or TrangaTask.ExecutionState.Enqueued)
.OrderBy(tmpTask => tmpTask.nextExecution).ToArray();
foreach (TrangaTask task in tmp)
{
task.state = TrangaTask.ExecutionState.Enqueued;