mirror of
https://github.com/C9Glax/tranga-website.git
synced 2025-07-02 08:54:17 +02:00
Moved files
Added DownloadClient to Connector
This commit is contained in:
52
Tranga/TaskManager.cs
Normal file
52
Tranga/TaskManager.cs
Normal file
@ -0,0 +1,52 @@
|
||||
namespace Tranga;
|
||||
|
||||
public class TaskManager
|
||||
{
|
||||
private readonly Dictionary<Publication, TrangaTask> _allTasks;
|
||||
private bool _continueRunning = true;
|
||||
|
||||
public TaskManager()
|
||||
{
|
||||
_allTasks = new Dictionary<Publication, TrangaTask>();
|
||||
Thread taskChecker = new(TaskCheckerThread);
|
||||
taskChecker.Start();
|
||||
}
|
||||
|
||||
private void TaskCheckerThread()
|
||||
{
|
||||
while (_continueRunning)
|
||||
{
|
||||
foreach (TrangaTask task in _allTasks.Values.Where(tt => (DateTime.Now - tt.lastExecuted) > tt.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()
|
||||
{
|
||||
return _allTasks.Keys.ToArray();
|
||||
}
|
||||
|
||||
public TrangaTask[] GetTasks()
|
||||
{
|
||||
return _allTasks.Values.ToArray();
|
||||
}
|
||||
|
||||
public void Shutdown()
|
||||
{
|
||||
_continueRunning = false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user