diff --git a/Tranga/TrangaTask.cs b/Tranga/TrangaTask.cs
index 828c6ac..6cd8a10 100644
--- a/Tranga/TrangaTask.cs
+++ b/Tranga/TrangaTask.cs
@@ -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
}
///
- /// Set state to running
+ /// Should call StartExecutionChores and EndExecutionChores
///
///
- public abstract void Execute(TaskManager taskManager);
+ ///
+ public abstract void Execute(TaskManager taskManager, Logger? logger);
/// True if elapsed time since last execution is greater than set interval
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,
diff --git a/Tranga/TrangaTasks/DownloadNewChaptersTask.cs b/Tranga/TrangaTasks/DownloadNewChaptersTask.cs
index 57a7738..41d2106 100644
--- a/Tranga/TrangaTasks/DownloadNewChaptersTask.cs
+++ b/Tranga/TrangaTasks/DownloadNewChaptersTask.cs
@@ -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);
}
///
diff --git a/Tranga/TrangaTasks/UpdateKomgaLibraryTask.cs b/Tranga/TrangaTasks/UpdateKomgaLibraryTask.cs
index d27c38e..c066347 100644
--- a/Tranga/TrangaTasks/UpdateKomgaLibraryTask.cs
+++ b/Tranga/TrangaTasks/UpdateKomgaLibraryTask.cs
@@ -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);
}
}
\ No newline at end of file