mirror of
https://github.com/C9Glax/tranga.git
synced 2025-02-23 07:40:13 +01:00
Jobs change RunningJobs to Dictionary of Thread and Job instead of just List of threads
This commit is contained in:
parent
84388a469a
commit
df319e9afb
@ -10,7 +10,7 @@ public static class Tranga
|
|||||||
{
|
{
|
||||||
public static Thread NotificationSenderThread { get; } = new (NotificationSender);
|
public static Thread NotificationSenderThread { get; } = new (NotificationSender);
|
||||||
public static Thread JobStarterThread { get; } = new (JobStarter);
|
public static Thread JobStarterThread { get; } = new (JobStarter);
|
||||||
private static readonly List<Thread> RunningJobs = new();
|
private static readonly Dictionary<Thread, Job> RunningJobs = new();
|
||||||
private static readonly ILog Log = LogManager.GetLogger(typeof(Tranga));
|
private static readonly ILog Log = LogManager.GetLogger(typeof(Tranga));
|
||||||
|
|
||||||
internal static void StartLogger()
|
internal static void StartLogger()
|
||||||
@ -63,6 +63,7 @@ public static class Tranga
|
|||||||
|
|
||||||
string TRANGA = "\n\n _______ \n|_ _|.----..---.-..-----..-----..---.-.\n | | | _|| _ || || _ || _ |\n |___| |__| |___._||__|__||___ ||___._|\n |_____| \n\n";
|
string TRANGA = "\n\n _______ \n|_ _|.----..---.-..-----..-----..---.-.\n | | | _|| _ || || _ || _ |\n |___| |__| |___._||__|__||___ ||___._|\n |_____| \n\n";
|
||||||
Log.Info(TRANGA);
|
Log.Info(TRANGA);
|
||||||
|
List<Job> newJobs = new();
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
List<Job> completedJobs = context.Jobs.Where(j => j.state == JobState.Completed).ToList();
|
List<Job> completedJobs = context.Jobs.Where(j => j.state == JobState.Completed).ToList();
|
||||||
@ -81,17 +82,22 @@ public static class Tranga
|
|||||||
{
|
{
|
||||||
Thread t = new (() =>
|
Thread t = new (() =>
|
||||||
{
|
{
|
||||||
IEnumerable<Job> newJobs = job.Run();
|
newJobs.AddRange(job.Run());
|
||||||
context.Jobs.AddRange(newJobs);
|
|
||||||
});
|
});
|
||||||
RunningJobs.Add(t);
|
RunningJobs.Add(t, job);
|
||||||
t.Start();
|
t.Start();
|
||||||
context.Jobs.Update(job);
|
context.Jobs.Update(job);
|
||||||
}
|
}
|
||||||
|
context.Jobs.AddRange(newJobs);
|
||||||
|
newJobs.Clear();
|
||||||
|
|
||||||
Thread[] removeFromThreadsList = RunningJobs.Where(t => !t.IsAlive).ToArray();
|
(Thread, Job)[] removeFromThreadsList = RunningJobs.Where(t => !t.Key.IsAlive)
|
||||||
foreach (Thread thread in removeFromThreadsList)
|
.Select(t => (t.Key, t.Value)).ToArray();
|
||||||
RunningJobs.Remove(thread);
|
foreach ((Thread thread, Job job) thread in removeFromThreadsList)
|
||||||
|
{
|
||||||
|
RunningJobs.Remove(thread.thread);
|
||||||
|
context.Jobs.Update(thread.job);
|
||||||
|
}
|
||||||
|
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
Thread.Sleep(2000);
|
Thread.Sleep(2000);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user