mirror of
https://github.com/C9Glax/tranga.git
synced 2025-01-12 11:27:32 +01:00
Fixed progress tracking this time for realsies. resolves #5
This commit is contained in:
parent
9ed36c47b5
commit
abc66511d8
@ -25,11 +25,11 @@ public abstract class TrangaTask
|
|||||||
public string taskId { get; init; }
|
public string taskId { get; init; }
|
||||||
[Newtonsoft.Json.JsonIgnore] public TrangaTask? parentTask { get; set; }
|
[Newtonsoft.Json.JsonIgnore] public TrangaTask? parentTask { get; set; }
|
||||||
public string? parentTaskId { get; set; }
|
public string? parentTaskId { get; set; }
|
||||||
[Newtonsoft.Json.JsonIgnore] protected HashSet<TrangaTask> childTasks { get; }
|
[Newtonsoft.Json.JsonIgnore] internal HashSet<TrangaTask> childTasks { get; }
|
||||||
public double progress => GetProgress();
|
public double progress => GetProgress();
|
||||||
[Newtonsoft.Json.JsonIgnore]public DateTime executionStarted { get; private set; }
|
[Newtonsoft.Json.JsonIgnore]public DateTime executionStarted { get; private set; }
|
||||||
[Newtonsoft.Json.JsonIgnore]public DateTime lastChange { get; private set; }
|
[Newtonsoft.Json.JsonIgnore]public DateTime lastChange { get; internal set; }
|
||||||
[Newtonsoft.Json.JsonIgnore]public DateTime executionApproximatelyFinished => progress != 0 ? lastChange.Add(GetRemainingTime()) : DateTime.MaxValue;
|
[Newtonsoft.Json.JsonIgnore]public DateTime executionApproximatelyFinished => lastChange.Add(GetRemainingTime());
|
||||||
public TimeSpan executionApproximatelyRemaining => executionApproximatelyFinished.Subtract(DateTime.Now);
|
public TimeSpan executionApproximatelyRemaining => executionApproximatelyFinished.Subtract(DateTime.Now);
|
||||||
[Newtonsoft.Json.JsonIgnore]public DateTime nextExecution => lastExecuted.Add(reoccurrence);
|
[Newtonsoft.Json.JsonIgnore]public DateTime nextExecution => lastExecuted.Add(reoccurrence);
|
||||||
|
|
||||||
@ -72,11 +72,16 @@ public abstract class TrangaTask
|
|||||||
this.state = ExecutionState.Running;
|
this.state = ExecutionState.Running;
|
||||||
this.executionStarted = DateTime.Now;
|
this.executionStarted = DateTime.Now;
|
||||||
this.lastChange = DateTime.Now;
|
this.lastChange = DateTime.Now;
|
||||||
|
if(parentTask is not null && parentTask.childTasks.All(ct => ct.state is ExecutionState.Waiting))
|
||||||
|
parentTask.executionStarted = DateTime.Now;
|
||||||
|
|
||||||
HttpStatusCode statusCode = ExecuteTask(taskManager, logger, cancellationToken);
|
HttpStatusCode statusCode = ExecuteTask(taskManager, logger, cancellationToken);
|
||||||
|
|
||||||
while(childTasks.Any(ct => ct.state is ExecutionState.Enqueued or ExecutionState.Running))
|
while(childTasks.Any(ct => ct.state is ExecutionState.Enqueued or ExecutionState.Running))
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
foreach(TrangaTask childTask in this.childTasks.ToArray())
|
foreach(TrangaTask childTask in this.childTasks.ToArray())
|
||||||
taskManager.DeleteTask(childTask);
|
taskManager.DeleteTask(childTask);
|
||||||
|
|
||||||
if ((int)statusCode >= 200 && (int)statusCode < 300)
|
if ((int)statusCode >= 200 && (int)statusCode < 300)
|
||||||
{
|
{
|
||||||
this.lastExecuted = DateTime.Now;
|
this.lastExecuted = DateTime.Now;
|
||||||
@ -108,10 +113,10 @@ public abstract class TrangaTask
|
|||||||
|
|
||||||
private TimeSpan GetRemainingTime()
|
private TimeSpan GetRemainingTime()
|
||||||
{
|
{
|
||||||
if(progress == 0 || lastChange == DateTime.MaxValue || executionStarted == DateTime.UnixEpoch)
|
if(progress == 0 || state is ExecutionState.Enqueued or ExecutionState.Waiting or ExecutionState.Failed || lastChange == DateTime.MaxValue)
|
||||||
return TimeSpan.Zero;
|
return DateTime.MaxValue.Subtract(lastChange).Subtract(TimeSpan.FromHours(1));
|
||||||
TimeSpan elapsed = lastChange.Subtract(executionStarted);
|
TimeSpan elapsed = lastChange.Subtract(executionStarted);
|
||||||
return elapsed.Divide(progress).Subtract(elapsed);
|
return elapsed.Divide(progress).Multiply(1 - progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Task : byte
|
public enum Task : byte
|
||||||
|
@ -47,6 +47,9 @@ public class DownloadChapterTask : TrangaTask
|
|||||||
internal void IncrementProgress(double amount)
|
internal void IncrementProgress(double amount)
|
||||||
{
|
{
|
||||||
this._dctProgress += amount;
|
this._dctProgress += amount;
|
||||||
|
this.lastChange = DateTime.Now;
|
||||||
|
if(this.parentTask is not null)
|
||||||
|
this.parentTask.lastChange = DateTime.Now;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user