debug
This commit is contained in:
parent
605bb6411f
commit
3e12baaafe
@ -64,7 +64,10 @@ namespace AutoClient.Modes
|
|||||||
{
|
{
|
||||||
var file = app.FolderWorkDispatcher.GetFileToCheck();
|
var file = app.FolderWorkDispatcher.GetFileToCheck();
|
||||||
var worker = new FileWorker(app, purchaseInfo, folder, file);
|
var worker = new FileWorker(app, purchaseInfo, folder, file);
|
||||||
await worker.Update(instance);
|
await worker.Update(instance, () =>
|
||||||
|
{
|
||||||
|
app.FolderWorkDispatcher.RevisitSoon(file);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Stop()
|
public void Stop()
|
||||||
@ -94,13 +97,13 @@ namespace AutoClient.Modes
|
|||||||
sourceFilename = filename;
|
sourceFilename = filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Update(ICodexInstance instance)
|
public async Task Update(ICodexInstance instance, Action shouldRevisitSoon)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var codex = new CodexNode(app, instance);
|
var codex = new CodexNode(app, instance);
|
||||||
await EnsureCid(instance, codex);
|
await EnsureCid(instance, codex);
|
||||||
await EnsureRecentPurchase(instance, codex);
|
await EnsureRecentPurchase(instance, codex, shouldRevisitSoon);
|
||||||
SaveState();
|
SaveState();
|
||||||
}
|
}
|
||||||
catch (Exception exc)
|
catch (Exception exc)
|
||||||
@ -110,13 +113,14 @@ namespace AutoClient.Modes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task EnsureRecentPurchase(ICodexInstance instance, CodexNode codex)
|
private async Task EnsureRecentPurchase(ICodexInstance instance, CodexNode codex, Action shouldRevisitSoon)
|
||||||
{
|
{
|
||||||
var recent = GetMostRecent();
|
var recent = GetMostRecent();
|
||||||
if (recent == null)
|
if (recent == null)
|
||||||
{
|
{
|
||||||
app.Log.Log($"No recent purchase for '{sourceFilename}'.");
|
app.Log.Log($"No recent purchase for '{sourceFilename}'.");
|
||||||
await MakeNewPurchase(instance, codex);
|
await MakeNewPurchase(instance, codex);
|
||||||
|
shouldRevisitSoon();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,6 +130,7 @@ namespace AutoClient.Modes
|
|||||||
{
|
{
|
||||||
app.Log.Log($"Recent purchase for '{sourceFilename}' has expired or finished.");
|
app.Log.Log($"Recent purchase for '{sourceFilename}' has expired or finished.");
|
||||||
await MakeNewPurchase(instance, codex);
|
await MakeNewPurchase(instance, codex);
|
||||||
|
shouldRevisitSoon();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,6 +139,7 @@ namespace AutoClient.Modes
|
|||||||
{
|
{
|
||||||
app.Log.Log($"Recent purchase for '{sourceFilename}' is going to expire soon.");
|
app.Log.Log($"Recent purchase for '{sourceFilename}' is going to expire soon.");
|
||||||
await MakeNewPurchase(instance, codex);
|
await MakeNewPurchase(instance, codex);
|
||||||
|
shouldRevisitSoon();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,10 +256,8 @@ namespace AutoClient.Modes
|
|||||||
private WorkerPurchase? GetMostRecent()
|
private WorkerPurchase? GetMostRecent()
|
||||||
{
|
{
|
||||||
if (!State.Purchases.Any()) return null;
|
if (!State.Purchases.Any()) return null;
|
||||||
var submitted = State.Purchases.Where(p => p.Submitted.HasValue).ToArray();
|
var maxCreated = State.Purchases.Max(p => p.Created);
|
||||||
if (submitted.Length == 0) return null;
|
return State.Purchases.SingleOrDefault(p => p.Created == maxCreated);
|
||||||
var maxSubmitted = submitted.Max(p => p.Submitted!.Value);
|
|
||||||
return State.Purchases.SingleOrDefault(p => p.Submitted.HasValue && p.Submitted.Value == maxSubmitted);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsCurrentlyRunning()
|
public bool IsCurrentlyRunning()
|
||||||
@ -301,6 +305,9 @@ namespace AutoClient.Modes
|
|||||||
public class FolderWorkDispatcher
|
public class FolderWorkDispatcher
|
||||||
{
|
{
|
||||||
private readonly List<string> files = new List<string>();
|
private readonly List<string> files = new List<string>();
|
||||||
|
private readonly List<string> revisitSoon = new List<string>();
|
||||||
|
private bool revisiting = false;
|
||||||
|
|
||||||
public FolderWorkDispatcher(string folder)
|
public FolderWorkDispatcher(string folder)
|
||||||
{
|
{
|
||||||
var fs = Directory.GetFiles(folder);
|
var fs = Directory.GetFiles(folder);
|
||||||
@ -319,10 +326,32 @@ namespace AutoClient.Modes
|
|||||||
|
|
||||||
public string GetFileToCheck()
|
public string GetFileToCheck()
|
||||||
{
|
{
|
||||||
var file = files.First();
|
if (revisiting)
|
||||||
files.RemoveAt(0);
|
{
|
||||||
files.Add(file);
|
if (!revisitSoon.Any())
|
||||||
return file;
|
{
|
||||||
|
revisiting = false;
|
||||||
|
return GetFileToCheck();
|
||||||
|
}
|
||||||
|
|
||||||
|
var file = revisitSoon.First();
|
||||||
|
revisitSoon.RemoveAt(0);
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var file = files.First();
|
||||||
|
files.RemoveAt(0);
|
||||||
|
files.Add(file);
|
||||||
|
|
||||||
|
if (revisitSoon.Count > 5) revisiting = true;
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RevisitSoon(string file)
|
||||||
|
{
|
||||||
|
revisitSoon.Add(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -350,7 +379,7 @@ namespace AutoClient.Modes
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var worker = new FileWorker(app, purchaseInfo, Folder, file);
|
var worker = new FileWorker(app, purchaseInfo, Folder, file.Substring(0, file.Length - 5));
|
||||||
total++;
|
total++;
|
||||||
if (worker.IsCurrentlyRunning()) successful++;
|
if (worker.IsCurrentlyRunning()) successful++;
|
||||||
if (worker.IsCurrentlyFailed()) failed++;
|
if (worker.IsCurrentlyFailed()) failed++;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user