mirror of
https://github.com/C9Glax/tranga-website.git
synced 2025-07-06 02:44:17 +02:00
Logging and Chores in abstract class
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Tranga.TrangaTasks;
|
||||
|
||||
@ -37,10 +38,11 @@ public abstract class TrangaTask
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set state to running
|
||||
/// Should call StartExecutionChores and EndExecutionChores
|
||||
/// </summary>
|
||||
/// <param name="taskManager"></param>
|
||||
public abstract void Execute(TaskManager taskManager);
|
||||
/// <param name="logger"></param>
|
||||
public abstract void Execute(TaskManager taskManager, Logger? logger);
|
||||
|
||||
/// <returns>True if elapsed time since last execution is greater than set interval</returns>
|
||||
public bool ShouldExecute()
|
||||
@ -48,6 +50,19 @@ public abstract class TrangaTask
|
||||
return DateTime.Now.Subtract(this.lastExecuted) > reoccurrence && state is ExecutionState.Waiting;
|
||||
}
|
||||
|
||||
protected void StartExecutionChores(Logger? logger)
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Executing Task {this}");
|
||||
this.state = ExecutionState.Running;
|
||||
}
|
||||
|
||||
protected void EndExecutionChores(Logger? logger)
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Finished Executing Task {this}");
|
||||
this.lastExecuted = DateTime.Now;
|
||||
this.state = ExecutionState.Waiting;
|
||||
}
|
||||
|
||||
public enum Task : byte
|
||||
{
|
||||
DownloadNewChapters = 2,
|
||||
|
Reference in New Issue
Block a user