2
0

Improved logic on QueueContainsJob and AddJobTo Queue

Added some documentation
This commit is contained in:
glax 2023-10-04 09:38:40 +02:00
parent d3ccddd8db
commit 4156365b18

View File

@ -37,6 +37,10 @@ public class JobBoss : GlobalBase
AddJob(job); AddJob(job);
} }
/// <summary>
/// Compares contents of the provided job and all current jobs
/// Does not check if objects are the same
/// </summary>
public bool ContainsJobLike(Job job) public bool ContainsJobLike(Job job)
{ {
if (job is DownloadChapter dcJob) if (job is DownloadChapter dcJob)
@ -123,17 +127,16 @@ public class JobBoss : GlobalBase
private bool QueueContainsJob(Job job) private bool QueueContainsJob(Job job)
{ {
mangaConnectorJobQueue.TryAdd(job.mangaConnector, new Queue<Job>()); if (mangaConnectorJobQueue.TryAdd(job.mangaConnector, new Queue<Job>()))//If we can add the queue, there is certainly no job in it
return true;
return mangaConnectorJobQueue[job.mangaConnector].Contains(job); return mangaConnectorJobQueue[job.mangaConnector].Contains(job);
} }
public void AddJobToQueue(Job job) public void AddJobToQueue(Job job)
{ {
Log($"Adding Job to Queue. {job}"); Log($"Adding Job to Queue. {job}");
mangaConnectorJobQueue.TryAdd(job.mangaConnector, new Queue<Job>()); if(!QueueContainsJob(job))
Queue<Job> connectorJobQueue = mangaConnectorJobQueue[job.mangaConnector]; mangaConnectorJobQueue[job.mangaConnector].Enqueue(job);
if(!connectorJobQueue.Contains(job))
connectorJobQueue.Enqueue(job);
job.ExecutionEnqueue(); job.ExecutionEnqueue();
} }