Slow down logging when waiting for requests to start.
This commit is contained in:
parent
23622245f0
commit
a40d5d77d7
@ -29,11 +29,22 @@ namespace AutoClient.Modes.FolderStore
|
||||
|
||||
public int FailureCounter => State.FailureCounter;
|
||||
|
||||
protected override void OnNewState(WorkerStatus newState)
|
||||
{
|
||||
newState.LastUpdate = DateTime.MinValue;
|
||||
}
|
||||
|
||||
public async Task Update()
|
||||
{
|
||||
try
|
||||
{
|
||||
Log($"Updating for '{sourceFilename}'...");
|
||||
if (IsCurrentlyRunning() && UpdatedRecently())
|
||||
{
|
||||
Log("Is running, was recently checked. Skip.");
|
||||
return;
|
||||
}
|
||||
|
||||
var cid = await EnsureCid();
|
||||
await EnsureRecentPurchase(cid);
|
||||
SaveState();
|
||||
@ -48,6 +59,12 @@ namespace AutoClient.Modes.FolderStore
|
||||
}
|
||||
}
|
||||
|
||||
private bool UpdatedRecently()
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
return State.LastUpdate + TimeSpan.FromHours(1) > now;
|
||||
}
|
||||
|
||||
private async Task<string> EnsureCid()
|
||||
{
|
||||
Log($"Checking CID...");
|
||||
@ -186,6 +203,7 @@ namespace AutoClient.Modes.FolderStore
|
||||
if (!recent.Started.HasValue) recent.Started = now;
|
||||
if (!recent.Finish.HasValue) recent.Finish = now;
|
||||
}
|
||||
State.LastUpdate = now;
|
||||
SaveState();
|
||||
}
|
||||
|
||||
@ -249,6 +267,7 @@ namespace AutoClient.Modes.FolderStore
|
||||
[Serializable]
|
||||
public class WorkerStatus
|
||||
{
|
||||
public DateTime LastUpdate { get; set; }
|
||||
public string Cid { get; set; } = string.Empty;
|
||||
public string EncodedCid { get; set; } = string.Empty;
|
||||
public int FailureCounter { get; set; } = 0;
|
||||
|
@ -21,6 +21,7 @@ namespace AutoClient.Modes.FolderStore
|
||||
if (!File.Exists(FilePath))
|
||||
{
|
||||
State = new T();
|
||||
OnNewState(State);
|
||||
SaveState();
|
||||
}
|
||||
var text = File.ReadAllText(FilePath);
|
||||
@ -37,6 +38,10 @@ namespace AutoClient.Modes.FolderStore
|
||||
protected string FilePath { get; }
|
||||
protected T State { get; private set; } = default!;
|
||||
|
||||
protected virtual void OnNewState(T newState)
|
||||
{
|
||||
}
|
||||
|
||||
protected void SaveState()
|
||||
{
|
||||
try
|
||||
|
Loading…
x
Reference in New Issue
Block a user