Better safe-duration

This commit is contained in:
Ben 2024-11-27 13:43:38 +01:00
parent a40d5d77d7
commit 513853d929
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
4 changed files with 20 additions and 15 deletions

View File

@ -38,13 +38,9 @@ namespace AutoClient.Modes.FolderStore
{
try
{
Log($"Updating for '{sourceFilename}'...");
if (IsCurrentlyRunning() && UpdatedRecently())
{
Log("Is running, was recently checked. Skip.");
return;
}
if (IsCurrentlyRunning() && UpdatedRecently()) return;
Log($"Updating for '{sourceFilename}'...");
var cid = await EnsureCid();
await EnsureRecentPurchase(cid);
SaveState();
@ -62,7 +58,7 @@ namespace AutoClient.Modes.FolderStore
private bool UpdatedRecently()
{
var now = DateTime.UtcNow;
return State.LastUpdate + TimeSpan.FromHours(1) > now;
return State.LastUpdate + TimeSpan.FromMinutes(15) > now;
}
private async Task<string> EnsureCid()

View File

@ -35,8 +35,8 @@ namespace AutoClient.Modes.FolderStore
log.Log("");
log.Log("Max number of busy workers reached. Waiting until contracts are started before creating any more.");
log.Log("");
Thread.Sleep(10000);
ResetIndex();
Thread.Sleep(TimeSpan.FromMinutes(1));
}
var file = new FileIndex(files[index], index);

View File

@ -2,7 +2,17 @@
{
public class PurchaseInfo
{
public TimeSpan PurchaseDurationTotal { get; set; }
public TimeSpan PurchaseDurationSafe { get; set; }
public PurchaseInfo(TimeSpan purchaseDurationTotal, TimeSpan purchaseDurationSafe)
{
PurchaseDurationTotal = purchaseDurationTotal;
PurchaseDurationSafe = purchaseDurationSafe;
if (PurchaseDurationTotal < TimeSpan.Zero) throw new Exception(nameof(PurchaseDurationTotal));
if (PurchaseDurationSafe < TimeSpan.Zero) throw new Exception(nameof(PurchaseDurationSafe));
if (PurchaseDurationTotal < PurchaseDurationSafe) throw new Exception("TotalDuration < SafeDuration");
}
public TimeSpan PurchaseDurationTotal { get; }
public TimeSpan PurchaseDurationSafe { get; }
}
}

View File

@ -68,11 +68,10 @@ public class Program
{
if (app.Config.ContractDurationMinutes - 1 < 5) throw new Exception("Contract duration config option not long enough!");
return new FolderStoreMode(app, app.Config.FolderToStore, new PurchaseInfo
{
PurchaseDurationTotal = TimeSpan.FromMinutes(app.Config.ContractDurationMinutes),
PurchaseDurationSafe = TimeSpan.FromMinutes(app.Config.ContractDurationMinutes - 1),
});
return new FolderStoreMode(app, app.Config.FolderToStore, new PurchaseInfo(
purchaseDurationTotal: TimeSpan.FromMinutes(app.Config.ContractDurationMinutes),
purchaseDurationSafe: TimeSpan.FromMinutes(app.Config.ContractDurationMinutes - 120)
));
}
private async Task<CodexInstance[]> CreateCodexInstances()