Tranga-Website/Tranga/TrangaTask.cs

38 lines
1.1 KiB
C#
Raw Normal View History

using System.Text.Json.Serialization;
namespace Tranga;
2023-05-18 21:08:09 +02:00
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 = "")
{
2023-05-18 21:08:09 +02:00
this.reoccurrence = reoccurrence;
this.lastExecuted = DateTime.Now.Subtract(reoccurrence);
this.connector = connector;
this.task = task;
this.publication = publication;
this.language = language;
2023-05-18 21:08:09 +02:00
}
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
}
}