Order of tasks closes #15
Also API /Queue/Get orders in order of nextExecution
This commit is contained in:
parent
8b916eb854
commit
234735a562
@ -196,7 +196,7 @@ app.MapGet("/Tasks/GetRunningTasks",
|
|||||||
() => taskManager.GetAllTasks().Where(task => task.state is TrangaTask.ExecutionState.Running));
|
() => taskManager.GetAllTasks().Where(task => task.state is TrangaTask.ExecutionState.Running));
|
||||||
|
|
||||||
app.MapGet("/Queue/GetList",
|
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) =>
|
app.MapPost("/Queue/Enqueue", (string taskType, string? connectorName, string? publicationId) =>
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Net;
|
using System.Globalization;
|
||||||
|
using System.Net;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using HtmlAgilityPack;
|
using HtmlAgilityPack;
|
||||||
using Logging;
|
using Logging;
|
||||||
@ -133,10 +134,17 @@ public class Manganato : Connector
|
|||||||
if (requestResult.statusCode != HttpStatusCode.OK)
|
if (requestResult.statusCode != HttpStatusCode.OK)
|
||||||
return Array.Empty<Chapter>();
|
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);
|
StreamReader reader = new (html);
|
||||||
string htmlString = reader.ReadToEnd();
|
string htmlString = reader.ReadToEnd();
|
||||||
@ -158,7 +166,7 @@ public class Manganato : Connector
|
|||||||
ret.Add(new Chapter(chapterName, volumeNumber, chapterNumber, url));
|
ret.Add(new Chapter(chapterName, volumeNumber, chapterNumber, url));
|
||||||
}
|
}
|
||||||
ret.Reverse();
|
ret.Reverse();
|
||||||
return ret.ToArray();
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DownloadChapter(Publication publication, Chapter chapter, DownloadChapterTask parentTask)
|
public override void DownloadChapter(Publication publication, Chapter chapter, DownloadChapterTask parentTask)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Net;
|
using System.Globalization;
|
||||||
|
using System.Net;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using HtmlAgilityPack;
|
using HtmlAgilityPack;
|
||||||
@ -200,8 +201,13 @@ public class Mangasee : Connector
|
|||||||
ret.Add(new Chapter("", volumeNumber, chapterNumber, url));
|
ret.Add(new Chapter("", volumeNumber, chapterNumber, url));
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.Reverse();
|
//Return Chapters ordered by Chapter-Number
|
||||||
return ret.ToArray();
|
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)
|
public override void DownloadChapter(Publication publication, Chapter chapter, DownloadChapterTask parentTask)
|
||||||
|
@ -90,7 +90,8 @@ public class TaskManager
|
|||||||
{
|
{
|
||||||
TrangaTask[] tmp = _allTasks.Where(taskQuery =>
|
TrangaTask[] tmp = _allTasks.Where(taskQuery =>
|
||||||
taskQuery.nextExecution < DateTime.Now &&
|
taskQuery.nextExecution < DateTime.Now &&
|
||||||
taskQuery.state is TrangaTask.ExecutionState.Waiting or TrangaTask.ExecutionState.Enqueued).ToArray();
|
taskQuery.state is TrangaTask.ExecutionState.Waiting or TrangaTask.ExecutionState.Enqueued)
|
||||||
|
.OrderBy(tmpTask => tmpTask.nextExecution).ToArray();
|
||||||
foreach (TrangaTask task in tmp)
|
foreach (TrangaTask task in tmp)
|
||||||
{
|
{
|
||||||
task.state = TrangaTask.ExecutionState.Enqueued;
|
task.state = TrangaTask.ExecutionState.Enqueued;
|
||||||
|
Loading…
Reference in New Issue
Block a user