Added fields to TrangaTask:

executionStarted,
executionApproximatelyFinished,
executionApproximatelyRemaining
to track progress
This commit is contained in:
glax 2023-06-06 21:19:30 +02:00
parent 17ce820cf3
commit 5c753e7a7d
2 changed files with 37 additions and 13 deletions

View File

@ -135,8 +135,12 @@ public static class Tranga_Cli
switch (selection) switch (selection)
{ {
case ConsoleKey.L: case ConsoleKey.L:
PrintTasks(taskManager.GetAllTasks(), logger); while (!Console.KeyAvailable)
Console.WriteLine("Press any key."); {
PrintTasks(taskManager.GetAllTasks(), logger);
Console.WriteLine("Press any key.");
Thread.Sleep(500);
}
Console.ReadKey(); Console.ReadKey();
break; break;
case ConsoleKey.C: case ConsoleKey.C:
@ -160,17 +164,26 @@ public static class Tranga_Cli
Console.ReadKey(); Console.ReadKey();
break; break;
case ConsoleKey.R: case ConsoleKey.R:
PrintTasks( while (!Console.KeyAvailable)
taskManager.GetAllTasks().Where(eTask => eTask.state == TrangaTask.ExecutionState.Running) {
.ToArray(), logger); PrintTasks(
Console.WriteLine("Press any key."); taskManager.GetAllTasks().Where(eTask => eTask.state == TrangaTask.ExecutionState.Running)
.ToArray(), logger);
Console.WriteLine("Press any key.");
Thread.Sleep(500);
}
Console.ReadKey(); Console.ReadKey();
break; break;
case ConsoleKey.K: case ConsoleKey.K:
PrintTasks( while (!Console.KeyAvailable)
taskManager.GetAllTasks().Where(qTask => qTask.state is TrangaTask.ExecutionState.Enqueued) {
.ToArray(), logger); PrintTasks(
Console.WriteLine("Press any key."); taskManager.GetAllTasks()
.Where(qTask => qTask.state is TrangaTask.ExecutionState.Enqueued)
.ToArray(), logger);
Console.WriteLine("Press any key.");
Thread.Sleep(500);
}
Console.ReadKey(); Console.ReadKey();
break; break;
case ConsoleKey.F: case ConsoleKey.F:
@ -240,13 +253,13 @@ public static class Tranga_Cli
int tIndex = 0; int tIndex = 0;
Console.WriteLine($"Tasks (Running/Queue/Total): {taskRunningCount}/{taskEnqueuedCount}/{taskCount}"); Console.WriteLine($"Tasks (Running/Queue/Total): {taskRunningCount}/{taskEnqueuedCount}/{taskCount}");
string header = string header =
$"{"",-5}{"Task",-20} | {"Last Executed",-20} | {"Reoccurrence",-12} | {"State",-10} | {"Progress",-9} | {"Connector",-15} | Publication/Manga "; $"{"",-5}{"Task",-20} | {"Last Executed",-20} | {"Reoccurrence",-12} | {"State",-10} | {"Progress",-9} | {"Finished",-20} | {"Remaining",-12} | {"Connector",-15} | Publication/Manga ";
Console.WriteLine(header); Console.WriteLine(header);
Console.WriteLine(new string('-', header.Length)); Console.WriteLine(new string('-', header.Length));
foreach (TrangaTask trangaTask in tasks) foreach (TrangaTask trangaTask in tasks)
{ {
string[] taskSplit = trangaTask.ToString().Split(", "); string[] taskSplit = trangaTask.ToString().Split(", ");
Console.WriteLine($"{tIndex++:000}: {taskSplit[0],-20} | {taskSplit[1],-20} | {taskSplit[2],-12} | {taskSplit[3],-10} | {(taskSplit.Length > 4 ? taskSplit[4] : ""),-9} | {(taskSplit.Length > 5 ? taskSplit[5] : ""),-15} | {(taskSplit.Length > 6 ? taskSplit[6] : "")} {(taskSplit.Length > 7 ? taskSplit[7] : "")} {(taskSplit.Length > 8 ? taskSplit[8] : "")}"); Console.WriteLine($"{tIndex++:000}: {taskSplit[0],-20} | {taskSplit[1],-20} | {taskSplit[2],-12} | {taskSplit[3],-10} | {taskSplit[4],-9} | {taskSplit[5],-20} | {taskSplit[6][..12],-12} | {(taskSplit.Length > 7 ? taskSplit[7] : ""),-15} | {(taskSplit.Length > 8 ? taskSplit[8] : "")} {(taskSplit.Length > 9 ? taskSplit[9] : "")} {(taskSplit.Length > 10 ? taskSplit[10] : "")}");
} }
} }

View File

@ -23,6 +23,15 @@ public abstract class TrangaTask
[Newtonsoft.Json.JsonIgnore]public ExecutionState state { get; set; } [Newtonsoft.Json.JsonIgnore]public ExecutionState state { get; set; }
[Newtonsoft.Json.JsonIgnore]public float progress { get; protected set; } [Newtonsoft.Json.JsonIgnore]public float progress { get; protected set; }
[Newtonsoft.Json.JsonIgnore]public DateTime nextExecution => lastExecuted.Add(reoccurrence); [Newtonsoft.Json.JsonIgnore]public DateTime nextExecution => lastExecuted.Add(reoccurrence);
[Newtonsoft.Json.JsonIgnore]public DateTime executionStarted { get; protected set; }
[Newtonsoft.Json.JsonIgnore]
public DateTime executionApproximatelyFinished => this.progress != 0
? this.executionStarted.Add(DateTime.Now.Subtract(this.executionStarted) / this.progress)
: DateTime.MaxValue;
[Newtonsoft.Json.JsonIgnore]
public TimeSpan executionApproximatelyRemaining => this.executionApproximatelyFinished.Subtract(DateTime.Now);
public enum ExecutionState public enum ExecutionState
{ {
@ -37,6 +46,7 @@ public abstract class TrangaTask
this.lastExecuted = DateTime.Now.Subtract(reoccurrence); this.lastExecuted = DateTime.Now.Subtract(reoccurrence);
this.task = task; this.task = task;
this.progress = 0f; this.progress = 0f;
this.executionStarted = DateTime.Now;
} }
public float IncrementProgress(float amount) public float IncrementProgress(float amount)
@ -61,6 +71,7 @@ public abstract class TrangaTask
{ {
logger?.WriteLine(this.GetType().ToString(), $"Executing Task {this}"); logger?.WriteLine(this.GetType().ToString(), $"Executing Task {this}");
this.state = ExecutionState.Running; this.state = ExecutionState.Running;
this.executionStarted = DateTime.Now;
ExecuteTask(taskManager, logger); ExecuteTask(taskManager, logger);
this.lastExecuted = DateTime.Now; this.lastExecuted = DateTime.Now;
this.state = ExecutionState.Waiting; this.state = ExecutionState.Waiting;
@ -82,7 +93,7 @@ public abstract class TrangaTask
public override string ToString() public override string ToString()
{ {
return $"{task}, {lastExecuted}, {reoccurrence}, {state}, {progress:P2}"; return $"{task}, {lastExecuted}, {reoccurrence}, {state}, {progress:P2}, {executionApproximatelyFinished}, {executionApproximatelyRemaining}";
} }
public class TrangaTaskJsonConverter : JsonConverter public class TrangaTaskJsonConverter : JsonConverter