Tranga-Website/Tranga/TrangaTask.cs
glax 6de6d060c4 Rewrite Task-Structure for serialization.
TrangaTask include information on what to execute where, do not execute tasks.
TaskExecutor executes Tasks on information from TrangaTask
2023-05-19 14:00:30 +02:00

38 lines
1.1 KiB
C#

using System.Text.Json.Serialization;
namespace Tranga;
public struct TrangaTask
{
[JsonInclude]public TimeSpan reoccurrence { get; }
[JsonInclude]public DateTime lastExecuted { get; set; }
[JsonInclude]public Connector connector { get; }
[JsonInclude]public Task task { get; }
[JsonInclude]public Publication publication { get; }
[JsonInclude]public string language { get; }
public TrangaTask(Connector connector, Task task, Publication publication, TimeSpan reoccurrence, string language = "")
{
this.reoccurrence = reoccurrence;
this.lastExecuted = DateTime.Now.Subtract(reoccurrence);
this.connector = connector;
this.task = task;
this.publication = publication;
this.language = language;
}
public bool ShouldExecute(bool willBeExecuted)
{
bool ret = (DateTime.Now - lastExecuted) > reoccurrence;
if (ret && willBeExecuted)
lastExecuted = DateTime.Now;
return ret;
}
public enum Task
{
UpdatePublications,
UpdateChapters,
DownloadNewChapters
}
}