#27 Starting job scans in order
This commit is contained in:
parent
c5ab4a73a6
commit
d3aa91f826
|
@ -92,6 +92,7 @@ namespace DML.AppCore.Classes
|
||||||
Debug($"Starting scan of guild {GuildId} channel {ChannelId}...");
|
Debug($"Starting scan of guild {GuildId} channel {ChannelId}...");
|
||||||
var result = new List<IMessage>();
|
var result = new List<IMessage>();
|
||||||
const ushort limit = 100;
|
const ushort limit = 100;
|
||||||
|
State = JobState.Scanning;
|
||||||
|
|
||||||
var finished = false;
|
var finished = false;
|
||||||
var scanStartTimeStamp = DateTime.UtcNow;
|
var scanStartTimeStamp = DateTime.UtcNow;
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
using Discord;
|
using Discord;
|
||||||
using DML.AppCore.Classes;
|
using DML.AppCore.Classes;
|
||||||
using SweetLib.Utils.Logger;
|
using SweetLib.Utils.Logger;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
@ -30,8 +29,10 @@ namespace DML.Application.Classes
|
||||||
|
|
||||||
private bool Run { get; set; } = false;
|
private bool Run { get; set; } = false;
|
||||||
public List<Job> JobList { get; set; } = new List<Job>();
|
public List<Job> JobList { get; set; } = new List<Job>();
|
||||||
public Dictionary<int, Queue<IMessage>> RunningJobs = new Dictionary<int, Queue<IMessage>>();
|
public Dictionary<int, Queue<IMessage>> RunningJobs { get; } = new Dictionary<int, Queue<IMessage>>();
|
||||||
internal int RunningThreads { get; set; } = 0;
|
internal int RunningThreads { get; set; } = 0;
|
||||||
|
internal Task SchedulerTask { get; private set; }
|
||||||
|
internal Task DownloadTask { get; private set; }
|
||||||
|
|
||||||
internal ulong MessagesScanned
|
internal ulong MessagesScanned
|
||||||
{
|
{
|
||||||
|
@ -87,44 +88,46 @@ namespace DML.Application.Classes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void StartScheduler()
|
||||||
|
{
|
||||||
|
Logger.Info("Starting scheduler jobs");
|
||||||
|
SchedulerTask = Task.Run(() =>
|
||||||
|
{
|
||||||
|
PerformSchedulerTask();
|
||||||
|
});
|
||||||
|
|
||||||
|
DownloadTask = Task.Run(() =>
|
||||||
|
{
|
||||||
|
PerformDownloads();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void Stop()
|
public void Stop()
|
||||||
{
|
{
|
||||||
Run = false;
|
Run = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ScanAll()
|
private async void PerformSchedulerTask()
|
||||||
{
|
{
|
||||||
Logger.Info("Started JobScheduler...");
|
Logger.Trace("SchedulerTask started");
|
||||||
|
foreach (var job in JobList)
|
||||||
|
{
|
||||||
|
if (job.State == JobState.Idle)
|
||||||
|
{
|
||||||
|
// scan all old messages first
|
||||||
|
Logger.Debug($"Starting scan for job {job.Id}");
|
||||||
|
await job.Scan();
|
||||||
|
job.State = JobState.Listening; // set to listening now
|
||||||
|
Logger.Debug($"Scan for job {job.Id} finished");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Logger.Trace("All jobs have been scanned");
|
||||||
|
}
|
||||||
|
|
||||||
Logger.Debug("Entering job list handler loop...");
|
private async void PerformDownloads()
|
||||||
//foreach (var job in JobList)
|
|
||||||
for (var i = JobList.Count - 1; i >= 0; i--)
|
|
||||||
{
|
{
|
||||||
if (JobList[i].State == JobState.Idle)
|
Logger.Trace("SchedulerTask started");
|
||||||
{
|
// TODO
|
||||||
try
|
|
||||||
{
|
|
||||||
var job = JobList[i];
|
|
||||||
Logger.Debug($"Checking job {job.Id}");
|
|
||||||
|
|
||||||
Task.Run(async () =>
|
|
||||||
{
|
|
||||||
var scanFinished = await job.Scan();
|
|
||||||
Logger.Trace($"Scan result of {job.Id}: {scanFinished}");
|
|
||||||
|
|
||||||
while (!scanFinished)
|
|
||||||
{
|
|
||||||
scanFinished = await job.Scan();
|
|
||||||
Logger.Trace($"Scan result of {job.Id}: {scanFinished}");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Logger.Error(ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -280,8 +280,9 @@ namespace DML.Application.Core
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings.RescanRequired = false;
|
// TODO
|
||||||
Settings.Store();
|
// Settings.RescanRequired = false;
|
||||||
|
// Settings.Store();
|
||||||
|
|
||||||
if (Settings.UseRPC)
|
if (Settings.UseRPC)
|
||||||
{
|
{
|
||||||
|
@ -309,7 +310,7 @@ namespace DML.Application.Core
|
||||||
splash.Close();
|
splash.Close();
|
||||||
|
|
||||||
Logger.Info("Starting scheduler...");
|
Logger.Info("Starting scheduler...");
|
||||||
Scheduler.ScanAll();
|
Scheduler.StartScheduler();
|
||||||
|
|
||||||
System.Windows.Forms.Application.Run(new MainForm());
|
System.Windows.Forms.Application.Run(new MainForm());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue