diff --git a/.idea/.idea.TaskQueue/.idea/workspace.xml b/.idea/.idea.TaskQueue/.idea/workspace.xml
index c268599..2fd6da7 100644
--- a/.idea/.idea.TaskQueue/.idea/workspace.xml
+++ b/.idea/.idea.TaskQueue/.idea/workspace.xml
@@ -5,18 +5,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -70,16 +59,47 @@
1708636916152
-
+
+
+
+ 1708641452330
+
+
+
+ 1708641452330
+
+
+
+ 1708641518087
+
+
+
+ 1708641518087
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/JobQueue/Job.cs b/JobQueue/Job.cs
index c924081..9fd14ce 100644
--- a/JobQueue/Job.cs
+++ b/JobQueue/Job.cs
@@ -43,7 +43,7 @@ public abstract class Job : IComparable
this.LastStarted = DateTime.UtcNow;
this.ProgressToken.Start();
this._logger?.LogDebug($"Started Job {JobId}");
- this.Execute(ProgressToken._cancellationTokenSource.Token);
+ this.Execute(ProgressToken.CancellationTokenSource.Token);
}
public void Cancel()
@@ -54,7 +54,7 @@ public abstract class Job : IComparable
public void Reset()
{
- this.ProgressToken._cancellationTokenSource.Cancel();
+ this.ProgressToken.CancellationTokenSource.Cancel();
this.ProgressToken = ProgressToken.Clone();
}
diff --git a/JobQueue/JobQueue.cs b/JobQueue/JobQueue.cs
index 0accdab..30477e9 100644
--- a/JobQueue/JobQueue.cs
+++ b/JobQueue/JobQueue.cs
@@ -5,7 +5,7 @@ namespace JobQueue;
public class JobQueue : IDisposable where T : notnull
{
private readonly Dictionary> _queues = new();
- public Dictionary> FailedJobs { get; init; } = new();
+ private Dictionary> FailedJobs { get; init; } = new();
private bool _running = true;
private readonly ILogger? _logger;
@@ -26,8 +26,8 @@ public class JobQueue : IDisposable where T : notnull
startJob?.Start();
}
- foreach (Job job in _queues.Values.Select(queue =>
- queue.Select(job => job.ProgressToken.State is ProgressState.Finished or ProgressState.Cancelled)))
+ foreach (Job job in _queues.Values.SelectMany(job => job).Where(job =>
+ job.ProgressToken.State is ProgressState.Finished or ProgressState.Cancelled))
{
this._logger?.LogInformation($"Job finished: {job}");
job.Reset();
@@ -99,7 +99,7 @@ public class JobQueue : IDisposable where T : notnull
{
this._logger?.LogInformation("Shutting down JobQueue.");
_running = false;
- foreach(Job job in _queues.Values.Select(set => set.Select(_ => true)))
+ foreach(Job job in _queues.Values.SelectMany(list => list))
job.Cancel();
}
}
\ No newline at end of file
diff --git a/JobQueue/ProgressToken.cs b/JobQueue/ProgressToken.cs
index 34de01c..dc909be 100644
--- a/JobQueue/ProgressToken.cs
+++ b/JobQueue/ProgressToken.cs
@@ -9,7 +9,7 @@ public struct ProgressToken
public float Progress { get; private set; }
public int? Steps { get; init; }
public int? FinishedSteps { get; private set; }
- internal CancellationTokenSource _cancellationTokenSource { get; } = new();
+ internal CancellationTokenSource CancellationTokenSource { get; } = new();
private readonly ILogger? _logger;
public ProgressToken(int? steps = null, ILogger? logger = null)
@@ -47,13 +47,13 @@ public struct ProgressToken
public void Start() => ChangeState(ProgressState.Running);
public void Cancel()
{
- _cancellationTokenSource.Cancel();
+ CancellationTokenSource.Cancel();
ChangeState(ProgressState.Cancelled);
}
public void MarkFailed()
{
- _cancellationTokenSource.Cancel();
+ CancellationTokenSource.Cancel();
ChangeState(ProgressState.Failed);
}