Compare commits
No commits in common. "b6f8c8aab50f6a806f61dcb015422a068463bf15" and "9fd8bf17413542a11bf7f4611affd6ac812a4b7c" have entirely different histories.
b6f8c8aab5
...
9fd8bf1741
@ -128,6 +128,7 @@ public class TaskManager
|
|||||||
DateTime.Now.Subtract(removeTask.Key.lastChange) > TimeSpan.FromMinutes(3))//3 Minutes since last update to task -> remove
|
DateTime.Now.Subtract(removeTask.Key.lastChange) > TimeSpan.FromMinutes(3))//3 Minutes since last update to task -> remove
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Disposing failed task {removeTask.Key}.");
|
logger?.WriteLine(this.GetType().ToString(), $"Disposing failed task {removeTask.Key}.");
|
||||||
|
removeTask.Key.parentTask?.DecrementProgress(removeTask.Key.progress);
|
||||||
removeTask.Value.Cancel();
|
removeTask.Value.Cancel();
|
||||||
toRemove.Add(removeTask.Key);
|
toRemove.Add(removeTask.Key);
|
||||||
}
|
}
|
||||||
|
@ -23,31 +23,50 @@ public abstract class TrangaTask
|
|||||||
public Task task { get; }
|
public Task task { get; }
|
||||||
public string taskId { get; set; }
|
public string taskId { get; set; }
|
||||||
[Newtonsoft.Json.JsonIgnore]public ExecutionState state { get; set; }
|
[Newtonsoft.Json.JsonIgnore]public ExecutionState state { get; set; }
|
||||||
[Newtonsoft.Json.JsonIgnore]protected HashSet<TrangaTask> childTasks { get; }
|
[Newtonsoft.Json.JsonIgnore]public double progress { get; protected set; }
|
||||||
[Newtonsoft.Json.JsonIgnore]public double progress => childTasks.Count > 0 ? childTasks.Sum(childTask => childTask.progress) / childTasks.Count : _myProgress;
|
|
||||||
[Newtonsoft.Json.JsonIgnore]private double _myProgress = 0;
|
|
||||||
[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; private 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
|
||||||
? this.executionStarted.Add(DateTime.Now.Subtract(this.executionStarted).Divide(this.progress))
|
? this.executionStarted.Add(DateTime.Now.Subtract(this.executionStarted) / this.progress)
|
||||||
: DateTime.MaxValue;
|
: DateTime.MaxValue;
|
||||||
|
|
||||||
[Newtonsoft.Json.JsonIgnore]public TimeSpan executionApproximatelyRemaining => this.executionApproximatelyFinished.Subtract(DateTime.Now);
|
[Newtonsoft.Json.JsonIgnore]
|
||||||
|
public TimeSpan executionApproximatelyRemaining => this.executionApproximatelyFinished.Subtract(DateTime.Now);
|
||||||
|
|
||||||
[Newtonsoft.Json.JsonIgnore]public DateTime lastChange { get; private set; }
|
[Newtonsoft.Json.JsonIgnore]public DateTime lastChange { get; private set; }
|
||||||
|
|
||||||
public enum ExecutionState { Waiting, Enqueued, Running }
|
public enum ExecutionState
|
||||||
|
{
|
||||||
|
Waiting,
|
||||||
|
Enqueued,
|
||||||
|
Running
|
||||||
|
};
|
||||||
|
|
||||||
protected TrangaTask(Task task, TimeSpan reoccurrence)
|
protected TrangaTask(Task task, TimeSpan reoccurrence)
|
||||||
{
|
{
|
||||||
this.reoccurrence = reoccurrence;
|
this.reoccurrence = reoccurrence;
|
||||||
this.lastExecuted = DateTime.Now.Subtract(reoccurrence);
|
this.lastExecuted = DateTime.Now.Subtract(reoccurrence);
|
||||||
this.task = task;
|
this.task = task;
|
||||||
|
this.progress = 0f;
|
||||||
this.executionStarted = DateTime.Now;
|
this.executionStarted = DateTime.Now;
|
||||||
this.lastChange = DateTime.MaxValue;
|
this.lastChange = DateTime.MaxValue;
|
||||||
this.taskId = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(this.executionStarted.ToString(CultureInfo.InvariantCulture)));
|
this.taskId = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(this.executionStarted.ToString(CultureInfo.InvariantCulture)));
|
||||||
this.childTasks = new();
|
}
|
||||||
|
|
||||||
|
public double IncrementProgress(double amount)
|
||||||
|
{
|
||||||
|
this.progress += amount;
|
||||||
|
this.lastChange = DateTime.Now;
|
||||||
|
return this.progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double DecrementProgress(double amount)
|
||||||
|
{
|
||||||
|
this.progress -= amount;
|
||||||
|
this.lastChange = DateTime.Now;
|
||||||
|
return this.progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -76,22 +95,10 @@ public abstract class TrangaTask
|
|||||||
logger?.WriteLine(this.GetType().ToString(), $"Finished Executing Task {this}");
|
logger?.WriteLine(this.GetType().ToString(), $"Finished Executing Task {this}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReplaceFailedChildTask(DownloadChapterTask failed, DownloadChapterTask newTask)
|
/// <returns>True if elapsed time since last execution is greater than set interval</returns>
|
||||||
|
public bool ShouldExecute()
|
||||||
{
|
{
|
||||||
if (!this.childTasks.Contains(failed))
|
return nextExecution < DateTime.Now && state is ExecutionState.Waiting;
|
||||||
throw new ArgumentException($"Task {failed} is not childTask of {this}");
|
|
||||||
this.childTasks.Remove(failed);
|
|
||||||
this.childTasks.Add(newTask);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddChildTask(DownloadChapterTask childTask)
|
|
||||||
{
|
|
||||||
this.childTasks.Add(childTask);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void IncrementProgress(double amount)
|
|
||||||
{
|
|
||||||
this._myProgress += amount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Task : byte
|
public enum Task : byte
|
||||||
|
@ -11,7 +11,6 @@ public class DownloadChapterTask : TrangaTask
|
|||||||
public Chapter chapter { get; }
|
public Chapter chapter { get; }
|
||||||
[JsonIgnore]public DownloadNewChaptersTask? parentTask { get; set; }
|
[JsonIgnore]public DownloadNewChaptersTask? parentTask { get; set; }
|
||||||
public string? parentTaskId { get; set; }
|
public string? parentTaskId { get; set; }
|
||||||
[JsonIgnore]public new double progress { get; private set; }
|
|
||||||
|
|
||||||
|
|
||||||
public DownloadChapterTask(Task task, string connectorName, Publication publication, Chapter chapter, string language = "en", DownloadNewChaptersTask? parentTask = null) : base(task, TimeSpan.Zero)
|
public DownloadChapterTask(Task task, string connectorName, Publication publication, Chapter chapter, string language = "en", DownloadNewChaptersTask? parentTask = null) : base(task, TimeSpan.Zero)
|
||||||
@ -22,7 +21,6 @@ public class DownloadChapterTask : TrangaTask
|
|||||||
this.language = language;
|
this.language = language;
|
||||||
this.parentTask = parentTask;
|
this.parentTask = parentTask;
|
||||||
this.parentTaskId = parentTask?.taskId;
|
this.parentTaskId = parentTask?.taskId;
|
||||||
this.progress = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void ExecuteTask(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null)
|
protected override void ExecuteTask(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null)
|
||||||
|
@ -8,11 +8,15 @@ public class DownloadNewChaptersTask : TrangaTask
|
|||||||
public string connectorName { get; }
|
public string connectorName { get; }
|
||||||
public Publication publication { get; }
|
public Publication publication { get; }
|
||||||
public string language { get; }
|
public string language { get; }
|
||||||
|
[JsonIgnore]private HashSet<DownloadChapterTask> childTasks { get; }
|
||||||
|
[JsonIgnore]public new double progress => childTasks.Count > 0 ? childTasks.Sum(childTask => childTask.progress) / childTasks.Count : 0;
|
||||||
|
|
||||||
public DownloadNewChaptersTask(Task task, string connectorName, Publication publication, TimeSpan reoccurrence, string language = "en") : base(task, reoccurrence)
|
public DownloadNewChaptersTask(Task task, string connectorName, Publication publication, TimeSpan reoccurrence, string language = "en") : base(task, reoccurrence)
|
||||||
{
|
{
|
||||||
this.connectorName = connectorName;
|
this.connectorName = connectorName;
|
||||||
this.publication = publication;
|
this.publication = publication;
|
||||||
this.language = language;
|
this.language = language;
|
||||||
|
this.childTasks = new();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void ExecuteTask(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null)
|
protected override void ExecuteTask(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null)
|
||||||
@ -38,6 +42,19 @@ public class DownloadNewChaptersTask : TrangaTask
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ReplaceFailedChildTask(DownloadChapterTask failed, DownloadChapterTask newTask)
|
||||||
|
{
|
||||||
|
if (!this.childTasks.Contains(failed))
|
||||||
|
throw new ArgumentException($"Task {failed} is not childTask of {this}");
|
||||||
|
this.childTasks.Remove(failed);
|
||||||
|
this.childTasks.Add(newTask);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddChildTask(DownloadChapterTask childTask)
|
||||||
|
{
|
||||||
|
this.childTasks.Add(childTask);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates the available Chapters of a Publication
|
/// Updates the available Chapters of a Publication
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -14,6 +14,6 @@ public class UpdateLibrariesTask : TrangaTask
|
|||||||
return;
|
return;
|
||||||
foreach(LibraryManager lm in taskManager.settings.libraryManagers)
|
foreach(LibraryManager lm in taskManager.settings.libraryManagers)
|
||||||
lm.UpdateLibrary();
|
lm.UpdateLibrary();
|
||||||
IncrementProgress(1);
|
this.progress = 1f;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -366,14 +366,9 @@ function ShowTasksQueue(){
|
|||||||
.then(json => {
|
.then(json => {
|
||||||
tagTasksRunning.innerText = json.length;
|
tagTasksRunning.innerText = json.length;
|
||||||
json.forEach(task => {
|
json.forEach(task => {
|
||||||
if(task.task == 2 || task.task == 4) {
|
downloadTasksOutput.appendChild(CreateProgressChild(task));
|
||||||
downloadTasksOutput.appendChild(CreateProgressChild(task));
|
document.querySelector(`#progress${task.taskId.replaceAll('=','')}`).value = task.progress;
|
||||||
document.querySelector(`#progress${task.taskId.replaceAll('=', '')}`).value = task.progress;
|
document.querySelector(`#progressStr${task.taskId.replaceAll('=','')}`).innerText = task.progress.toLocaleString(undefined,{style: 'percent', minimumFractionDigits:2});
|
||||||
var finishedHours = task.executionApproximatelyRemaining.split(':')[0];
|
|
||||||
var finishedMinutes = task.executionApproximatelyRemaining.split(':')[1];
|
|
||||||
var finishedSeconds = task.executionApproximatelyRemaining.split(':')[2].split('.')[0];
|
|
||||||
document.querySelector(`#progressStr${task.taskId.replaceAll('=', '')}`).innerText = `${finishedHours}:${finishedMinutes}:${finishedSeconds}`;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -404,7 +399,7 @@ function CreateProgressChild(task){
|
|||||||
child.appendChild(progress);
|
child.appendChild(progress);
|
||||||
|
|
||||||
var progressStr = document.createElement("span");
|
var progressStr = document.createElement("span");
|
||||||
progressStr.innerText = " \t∞";
|
progressStr.innerText = "00.00%";
|
||||||
progressStr.className = "progressStr";
|
progressStr.className = "progressStr";
|
||||||
progressStr.id = `progressStr${task.taskId.replaceAll('=','')}`;
|
progressStr.id = `progressStr${task.taskId.replaceAll('=','')}`;
|
||||||
child.appendChild(progressStr);
|
child.appendChild(progressStr);
|
||||||
@ -489,13 +484,8 @@ setInterval(() => {
|
|||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
GetRunningTasks().then((json) => {
|
GetRunningTasks().then((json) => {
|
||||||
json.forEach(task => {
|
json.forEach(task => {
|
||||||
if(task.task == 2 || task.task == 4){
|
document.querySelector(`#progress${task.taskId.replaceAll('=','')}`).value = task.progress;
|
||||||
document.querySelector(`#progress${task.taskId.replaceAll('=','')}`).value = task.progress;
|
document.querySelector(`#progressStr${task.taskId.replaceAll('=','')}`).innerText = task.progress.toLocaleString(undefined,{style: 'percent', minimumFractionDigits:2});
|
||||||
var finishedHours = task.executionApproximatelyRemaining.split(':')[0];
|
|
||||||
var finishedMinutes = task.executionApproximatelyRemaining.split(':')[1];
|
|
||||||
var finishedSeconds = task.executionApproximatelyRemaining.split(':')[2].split('.')[0];
|
|
||||||
document.querySelector(`#progressStr${task.taskId.replaceAll('=','')}`).innerText = `${finishedHours}:${finishedMinutes}:${finishedSeconds}`;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},500);
|
},500);
|
Loading…
Reference in New Issue
Block a user