Rewrite of Task-System for serialization.

This commit is contained in:
2023-05-18 20:58:03 +02:00
parent db5470769c
commit 0fc146019a
2 changed files with 69 additions and 55 deletions

View File

@ -2,7 +2,7 @@
public class TaskManager
{
private readonly Dictionary<Publication, Chapter[]> _chapterCollection;
private Dictionary<Publication, Chapter[]> _chapterCollection;
private readonly HashSet<TrangaTask> _allTasks;
private bool _continueRunning = true;
@ -14,18 +14,18 @@ public class TaskManager
taskChecker.Start();
}
public void AddTask(Connector connector, TrangaTask.availableTasks task, TimeSpan reoccurrence, Publication? publication = null, string language = "en")
{
this._allTasks.Add(new TrangaTask(connector, task, reoccurrence, publication, language));
}
private void TaskCheckerThread()
{
while (_continueRunning)
{
foreach (TrangaTask task in _allTasks.Where(trangaTask => (DateTime.Now - trangaTask.lastExecuted) > trangaTask.reoccurrence))
{
if (!task.lastExecutedSuccessfully)
{
task.Abort();
//Add logging that task has failed
}
task.Execute();
task.Execute(ref _chapterCollection);
}
Thread.Sleep(1000);
}
@ -39,7 +39,7 @@ public class TaskManager
public Publication[] GetAddedPublications()
{
throw new NotImplementedException();
return this._chapterCollection.Keys.ToArray();
}
public TrangaTask[] GetTasks()