Tranga-Website/Tranga/TaskManager.cs
glax 943ce98f38 Tasks are now stored separately in Hashset
Created Dict<Publication, Chapter[]> _chapterCollection for added chapters.
2023-05-18 19:25:46 +02:00

54 lines
1.3 KiB
C#

namespace Tranga;
public class TaskManager
{
private readonly Dictionary<Publication, Chapter[]> _chapterCollection;
private readonly HashSet<TrangaTask> _allTasks;
private bool _continueRunning = true;
public TaskManager()
{
_chapterCollection = new();
_allTasks = new ();
Thread taskChecker = new(TaskCheckerThread);
taskChecker.Start();
}
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();
}
Thread.Sleep(1000);
}
}
public bool PublicationAlreadyAdded(Publication publication)
{
throw new NotImplementedException();
//TODO fuzzy check publications
}
public Publication[] GetAddedPublications()
{
throw new NotImplementedException();
}
public TrangaTask[] GetTasks()
{
return _allTasks.ToArray();
}
public void Shutdown()
{
_continueRunning = false;
}
}