mirror of
https://github.com/logos-storage/logos-storage-nim-cs-dist-tests.git
synced 2026-05-01 23:23:09 +00:00
Limits number of concurrently starting contracts
This commit is contained in:
parent
025c85c1aa
commit
9853a0b7db
@ -23,7 +23,7 @@ namespace AutoClient
|
||||
|
||||
if (!string.IsNullOrEmpty(config.FolderToStore))
|
||||
{
|
||||
FolderWorkDispatcher = new FolderWorkDispatcher(config.FolderToStore);
|
||||
FolderWorkDispatcher = new FolderWorkDispatcher(Log, config.FolderToStore);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -12,6 +12,19 @@ namespace AutoClient.Modes.FolderStore
|
||||
this.purchaseInfo = purchaseInfo;
|
||||
}
|
||||
|
||||
public bool IsBusy()
|
||||
{
|
||||
if (!State.Purchases.Any()) return false;
|
||||
|
||||
return State.Purchases.Any(p =>
|
||||
p.Submitted.HasValue &&
|
||||
!p.Started.HasValue &&
|
||||
!p.Expiry.HasValue &&
|
||||
!p.Finish.HasValue &&
|
||||
p.Created > DateTime.UtcNow - purchaseInfo.PurchaseDurationTotal
|
||||
);
|
||||
}
|
||||
|
||||
public bool IsCurrentlyRunning()
|
||||
{
|
||||
if (!State.Purchases.Any()) return false;
|
||||
|
||||
@ -1,11 +1,15 @@
|
||||
namespace AutoClient.Modes.FolderStore
|
||||
using Logging;
|
||||
|
||||
namespace AutoClient.Modes.FolderStore
|
||||
{
|
||||
public class FolderWorkDispatcher
|
||||
{
|
||||
private readonly string[] files = Array.Empty<string>();
|
||||
private readonly ILog log;
|
||||
private int index = 0;
|
||||
private int busyCount = 0;
|
||||
|
||||
public FolderWorkDispatcher(string folder)
|
||||
public FolderWorkDispatcher(ILog log, string folder)
|
||||
{
|
||||
var fs = Directory.GetFiles(folder);
|
||||
var result = new List<string>();
|
||||
@ -21,10 +25,17 @@
|
||||
}
|
||||
}
|
||||
files = result.ToArray();
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
public FileIndex GetFileToCheck()
|
||||
{
|
||||
if (busyCount > 1)
|
||||
{
|
||||
log.Log("Max number of busy workers reached. Waiting until contracts are started before creating any more.");
|
||||
ResetIndex();
|
||||
}
|
||||
|
||||
var file = new FileIndex(files[index], index);
|
||||
index = (index + 1) % files.Length;
|
||||
return file;
|
||||
@ -33,6 +44,12 @@
|
||||
public void ResetIndex()
|
||||
{
|
||||
index = 0;
|
||||
busyCount = 0;
|
||||
}
|
||||
|
||||
public void WorkerIsBusy()
|
||||
{
|
||||
busyCount++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -64,6 +64,7 @@ namespace AutoClient.Modes
|
||||
var file = app.FolderWorkDispatcher.GetFileToCheck();
|
||||
var worker = new FileWorker(app, instance, purchaseInfo, folder, file, OnFileUploaded, OnNewPurchase);
|
||||
await worker.Update();
|
||||
if (worker.IsBusy()) app.FolderWorkDispatcher.WorkerIsBusy();
|
||||
return worker;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user