2
0

#40 task timeout criteria

This commit is contained in:
glax 2023-06-07 00:27:53 +02:00
parent 1f3ac41b30
commit 87eade10cf
4 changed files with 8 additions and 2 deletions

View File

@ -124,7 +124,7 @@ public class TaskManager
foreach (KeyValuePair<DownloadChapterTask,Task> removeTask in _runningDownloadChapterTasks) foreach (KeyValuePair<DownloadChapterTask,Task> removeTask in _runningDownloadChapterTasks)
{ {
if (removeTask.Key.GetType() == typeof(DownloadChapterTask) && if (removeTask.Key.GetType() == typeof(DownloadChapterTask) &&
DateTime.Now.Subtract(removeTask.Key.executionStarted) > TimeSpan.FromMinutes(10))//TODO better way to check if task has failed? DateTime.Now.Subtract(removeTask.Key.lastChange) > TimeSpan.FromMinutes(3))//3 Minutes since last update to task -> remove
{ {
logger?.WriteLine(this.GetType().ToString(), $"Removing failed task {removeTask}."); logger?.WriteLine(this.GetType().ToString(), $"Removing failed task {removeTask}.");
removeTask.Value.Dispose(); removeTask.Value.Dispose();

View File

@ -23,7 +23,7 @@ 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 executionStarted { get; private set; }
[Newtonsoft.Json.JsonIgnore] [Newtonsoft.Json.JsonIgnore]
public DateTime executionApproximatelyFinished => this.progress != 0 public DateTime executionApproximatelyFinished => this.progress != 0
@ -33,6 +33,8 @@ public abstract class TrangaTask
[Newtonsoft.Json.JsonIgnore] [Newtonsoft.Json.JsonIgnore]
public TimeSpan executionApproximatelyRemaining => this.executionApproximatelyFinished.Subtract(DateTime.Now); public TimeSpan executionApproximatelyRemaining => this.executionApproximatelyFinished.Subtract(DateTime.Now);
[Newtonsoft.Json.JsonIgnore]public DateTime lastChange { get; protected set; }
public enum ExecutionState public enum ExecutionState
{ {
Waiting, Waiting,
@ -47,11 +49,13 @@ public abstract class TrangaTask
this.task = task; this.task = task;
this.progress = 0f; this.progress = 0f;
this.executionStarted = DateTime.Now; this.executionStarted = DateTime.Now;
this.lastChange = DateTime.Now;
} }
public float IncrementProgress(float amount) public float IncrementProgress(float amount)
{ {
this.progress += amount; this.progress += amount;
this.lastChange = DateTime.Now;
return this.progress; return this.progress;
} }

View File

@ -30,6 +30,7 @@ public class DownloadChapterTask : TrangaTask
public new float IncrementProgress(float amount) public new float IncrementProgress(float amount)
{ {
this.progress += amount; this.progress += amount;
this.lastChange = DateTime.Now;
parentTask?.IncrementProgress(amount); parentTask?.IncrementProgress(amount);
return this.progress; return this.progress;
} }

View File

@ -21,6 +21,7 @@ public class DownloadNewChaptersTask : TrangaTask
public new float IncrementProgress(float amount) public new float IncrementProgress(float amount)
{ {
this.progress += amount / this.childTaskAmount; this.progress += amount / this.childTaskAmount;
this.lastChange = DateTime.Now;
return this.progress; return this.progress;
} }