Logging and Chores in abstract class
This commit is contained in:
parent
8ff65bf400
commit
61ecefb615
@ -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,
|
||||
|
@ -1,4 +1,6 @@
|
||||
namespace Tranga.TrangaTasks;
|
||||
using Logging;
|
||||
|
||||
namespace Tranga.TrangaTasks;
|
||||
|
||||
public class DownloadNewChaptersTask : TrangaTask
|
||||
{
|
||||
@ -6,9 +8,9 @@ public class DownloadNewChaptersTask : TrangaTask
|
||||
{
|
||||
}
|
||||
|
||||
public override void Execute(TaskManager taskManager)
|
||||
public override void Execute(TaskManager taskManager, Logger? logger)
|
||||
{
|
||||
this.state = ExecutionState.Running;
|
||||
StartExecutionChores(logger);
|
||||
Publication pub = (Publication)this.publication!;
|
||||
Connector connector = taskManager.GetConnector(this.connectorName);
|
||||
|
||||
@ -25,8 +27,7 @@ public class DownloadNewChaptersTask : TrangaTask
|
||||
foreach(Chapter newChapter in newChapters)
|
||||
connector.DownloadChapter(pub, newChapter);
|
||||
|
||||
this.lastExecuted = DateTime.Now;
|
||||
this.state = ExecutionState.Waiting;
|
||||
EndExecutionChores(logger);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -1,4 +1,6 @@
|
||||
namespace Tranga.TrangaTasks;
|
||||
using Logging;
|
||||
|
||||
namespace Tranga.TrangaTasks;
|
||||
|
||||
public class UpdateKomgaLibraryTask : TrangaTask
|
||||
{
|
||||
@ -6,9 +8,9 @@ public class UpdateKomgaLibraryTask : TrangaTask
|
||||
{
|
||||
}
|
||||
|
||||
public override void Execute(TaskManager taskManager)
|
||||
public override void Execute(TaskManager taskManager, Logger? logger)
|
||||
{
|
||||
this.state = ExecutionState.Running;
|
||||
StartExecutionChores(logger);
|
||||
if (taskManager.komga is null)
|
||||
return;
|
||||
Komga komga = taskManager.komga;
|
||||
@ -16,8 +18,6 @@ public class UpdateKomgaLibraryTask : TrangaTask
|
||||
Komga.KomgaLibrary[] allLibraries = komga.GetLibraries();
|
||||
foreach (Komga.KomgaLibrary lib in allLibraries)
|
||||
komga.UpdateLibrary(lib.id);
|
||||
|
||||
this.lastExecuted = DateTime.Now;
|
||||
this.state = ExecutionState.Waiting;
|
||||
EndExecutionChores(logger);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user