mirror of
https://github.com/C9Glax/tranga-website.git
synced 2025-01-31 00:47:30 +01:00
Better/More logging
This commit is contained in:
parent
06a8e4e895
commit
e02b00e0ef
@ -21,7 +21,7 @@ public class MangaDex : Connector
|
|||||||
|
|
||||||
public override Publication[] GetPublications(string publicationTitle = "")
|
public override Publication[] GetPublications(string publicationTitle = "")
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Getting Publications");
|
logger?.WriteLine(this.GetType().ToString(), $"Getting Publications (title={publicationTitle})");
|
||||||
const int limit = 100; //How many values we want returned at once
|
const int limit = 100; //How many values we want returned at once
|
||||||
int offset = 0; //"Page"
|
int offset = 0; //"Page"
|
||||||
int total = int.MaxValue; //How many total results are there, is updated on first request
|
int total = int.MaxValue; //How many total results are there, is updated on first request
|
||||||
@ -128,7 +128,7 @@ public class MangaDex : Connector
|
|||||||
|
|
||||||
public override Chapter[] GetChapters(Publication publication, string language = "")
|
public override Chapter[] GetChapters(Publication publication, string language = "")
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Getting Chapters");
|
logger?.WriteLine(this.GetType().ToString(), $"Getting Chapters {publication.sortName} (language={language})");
|
||||||
const int limit = 100; //How many values we want returned at once
|
const int limit = 100; //How many values we want returned at once
|
||||||
int offset = 0; //"Page"
|
int offset = 0; //"Page"
|
||||||
int total = int.MaxValue; //How many total results are there, is updated on first request
|
int total = int.MaxValue; //How many total results are there, is updated on first request
|
||||||
@ -183,7 +183,7 @@ public class MangaDex : Connector
|
|||||||
|
|
||||||
public override void DownloadChapter(Publication publication, Chapter chapter)
|
public override void DownloadChapter(Publication publication, Chapter chapter)
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Download Chapter {publication.sortName} {chapter.sortNumber}");
|
logger?.WriteLine(this.GetType().ToString(), $"Download Chapter {publication.sortName} {chapter.volumeNumber}-{chapter.chapterNumber}");
|
||||||
//Request URLs for Chapter-Images
|
//Request URLs for Chapter-Images
|
||||||
DownloadClient.RequestResult requestResult =
|
DownloadClient.RequestResult requestResult =
|
||||||
downloadClient.MakeRequest($"https://api.mangadex.org/at-home/server/{chapter.url}?forcePort443=false'");
|
downloadClient.MakeRequest($"https://api.mangadex.org/at-home/server/{chapter.url}?forcePort443=false'");
|
||||||
|
@ -15,6 +15,7 @@ public static class TaskExecutor
|
|||||||
/// <param name="taskManager">Parent</param>
|
/// <param name="taskManager">Parent</param>
|
||||||
/// <param name="trangaTask">Task to execute</param>
|
/// <param name="trangaTask">Task to execute</param>
|
||||||
/// <param name="chapterCollection">Current chapterCollection to update</param>
|
/// <param name="chapterCollection">Current chapterCollection to update</param>
|
||||||
|
/// <param name="logger"></param>
|
||||||
/// <exception cref="ArgumentException">Is thrown when there is no Connector available with the name of the TrangaTask.connectorName</exception>
|
/// <exception cref="ArgumentException">Is thrown when there is no Connector available with the name of the TrangaTask.connectorName</exception>
|
||||||
public static void Execute(TaskManager taskManager, TrangaTask trangaTask, Dictionary<Publication, List<Chapter>> chapterCollection, Logger? logger)
|
public static void Execute(TaskManager taskManager, TrangaTask trangaTask, Dictionary<Publication, List<Chapter>> chapterCollection, Logger? logger)
|
||||||
{
|
{
|
||||||
@ -25,7 +26,7 @@ public static class TaskExecutor
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
trangaTask.state = TrangaTask.ExecutionState.Running;
|
trangaTask.state = TrangaTask.ExecutionState.Running;
|
||||||
logger?.WriteLine("TaskExecutor", $"Executing Task {trangaTask}");
|
logger?.WriteLine("TaskExecutor", $"Starting Task {trangaTask}");
|
||||||
|
|
||||||
//Connector is not needed for all tasks
|
//Connector is not needed for all tasks
|
||||||
Connector? connector = null;
|
Connector? connector = null;
|
||||||
@ -49,9 +50,9 @@ public static class TaskExecutor
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger?.WriteLine("TaskExecutor", $"Task executed! {trangaTask}");
|
logger?.WriteLine("TaskExecutor", $"Task finished! {trangaTask}");
|
||||||
trangaTask.state = TrangaTask.ExecutionState.Waiting;
|
|
||||||
trangaTask.lastExecuted = DateTime.Now;
|
trangaTask.lastExecuted = DateTime.Now;
|
||||||
|
trangaTask.state = TrangaTask.ExecutionState.Waiting;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -60,6 +60,7 @@ public class TaskManager
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void TaskCheckerThread()
|
private void TaskCheckerThread()
|
||||||
{
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), "Starting TaskCheckerThread.");
|
||||||
while (_continueRunning)
|
while (_continueRunning)
|
||||||
{
|
{
|
||||||
//Check if previous tasks have finished and execute new tasks
|
//Check if previous tasks have finished and execute new tasks
|
||||||
@ -120,7 +121,7 @@ public class TaskManager
|
|||||||
public TrangaTask AddTask(TrangaTask.Task task, string? connectorName, Publication? publication, TimeSpan reoccurrence,
|
public TrangaTask AddTask(TrangaTask.Task task, string? connectorName, Publication? publication, TimeSpan reoccurrence,
|
||||||
string language = "")
|
string language = "")
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Adding new Task");
|
logger?.WriteLine(this.GetType().ToString(), $"Adding new Task {task} {connectorName} {publication?.sortName}");
|
||||||
if (task != TrangaTask.Task.UpdateKomgaLibrary && connectorName is null)
|
if (task != TrangaTask.Task.UpdateKomgaLibrary && connectorName is null)
|
||||||
throw new ArgumentException($"connectorName can not be null for task {task}");
|
throw new ArgumentException($"connectorName can not be null for task {task}");
|
||||||
|
|
||||||
@ -154,7 +155,7 @@ public class TaskManager
|
|||||||
_allTasks.Add(newTask);
|
_allTasks.Add(newTask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger?.WriteLine(this.GetType().ToString(), newTask.ToString());
|
logger?.WriteLine(this.GetType().ToString(), $"Added new Task {newTask.ToString()}");
|
||||||
ExportData(Directory.GetCurrentDirectory());
|
ExportData(Directory.GetCurrentDirectory());
|
||||||
|
|
||||||
return newTask;
|
return newTask;
|
||||||
@ -168,15 +169,23 @@ public class TaskManager
|
|||||||
/// <param name="publication">Publication that was used</param>
|
/// <param name="publication">Publication that was used</param>
|
||||||
public void RemoveTask(TrangaTask.Task task, string? connectorName, Publication? publication)
|
public void RemoveTask(TrangaTask.Task task, string? connectorName, Publication? publication)
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Removing Task {task}");
|
logger?.WriteLine(this.GetType().ToString(), $"Removing Task {task} {publication?.sortName}");
|
||||||
if (task == TrangaTask.Task.UpdateKomgaLibrary)
|
if (task == TrangaTask.Task.UpdateKomgaLibrary)
|
||||||
|
{
|
||||||
_allTasks.RemoveWhere(uTask => uTask.task == TrangaTask.Task.UpdateKomgaLibrary);
|
_allTasks.RemoveWhere(uTask => uTask.task == TrangaTask.Task.UpdateKomgaLibrary);
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Removed Task {task}");
|
||||||
|
}
|
||||||
else if (connectorName is null)
|
else if (connectorName is null)
|
||||||
throw new ArgumentException($"connectorName can not be null for Task {task}");
|
throw new ArgumentException($"connectorName can not be null for Task {task}");
|
||||||
else
|
else
|
||||||
_allTasks.RemoveWhere(trangaTask =>
|
{
|
||||||
|
if(_allTasks.RemoveWhere(trangaTask =>
|
||||||
trangaTask.task == task && trangaTask.connectorName == connectorName &&
|
trangaTask.task == task && trangaTask.connectorName == connectorName &&
|
||||||
trangaTask.publication?.downloadUrl == publication?.downloadUrl);
|
trangaTask.publication?.downloadUrl == publication?.downloadUrl) > 0)
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Removed Task {task} {publication?.sortName} {publication?.downloadUrl}.");
|
||||||
|
else
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"No Task {task} {publication?.sortName} {publication?.downloadUrl} could be found.");
|
||||||
|
}
|
||||||
ExportData(Directory.GetCurrentDirectory());
|
ExportData(Directory.GetCurrentDirectory());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,6 +240,7 @@ public class TaskManager
|
|||||||
//Wait for tasks to finish
|
//Wait for tasks to finish
|
||||||
while(_allTasks.Any(task => task.state is TrangaTask.ExecutionState.Running or TrangaTask.ExecutionState.Enqueued))
|
while(_allTasks.Any(task => task.state is TrangaTask.ExecutionState.Running or TrangaTask.ExecutionState.Enqueued))
|
||||||
Thread.Sleep(10);
|
Thread.Sleep(10);
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), "Tasks finished. Bye!");
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user