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;
|
public int FailureCounter => State.FailureCounter;
|
||||||
|
|
||||||
|
protected override void OnNewState(WorkerStatus newState)
|
||||||
|
{
|
||||||
|
newState.LastUpdate = DateTime.MinValue;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task Update()
|
public async Task Update()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Log($"Updating for '{sourceFilename}'...");
|
Log($"Updating for '{sourceFilename}'...");
|
||||||
|
if (IsCurrentlyRunning() && UpdatedRecently())
|
||||||
|
{
|
||||||
|
Log("Is running, was recently checked. Skip.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var cid = await EnsureCid();
|
var cid = await EnsureCid();
|
||||||
await EnsureRecentPurchase(cid);
|
await EnsureRecentPurchase(cid);
|
||||||
SaveState();
|
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()
|
private async Task<string> EnsureCid()
|
||||||
{
|
{
|
||||||
Log($"Checking CID...");
|
Log($"Checking CID...");
|
||||||
@ -186,6 +203,7 @@ namespace AutoClient.Modes.FolderStore
|
|||||||
if (!recent.Started.HasValue) recent.Started = now;
|
if (!recent.Started.HasValue) recent.Started = now;
|
||||||
if (!recent.Finish.HasValue) recent.Finish = now;
|
if (!recent.Finish.HasValue) recent.Finish = now;
|
||||||
}
|
}
|
||||||
|
State.LastUpdate = now;
|
||||||
SaveState();
|
SaveState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,6 +267,7 @@ namespace AutoClient.Modes.FolderStore
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public class WorkerStatus
|
public class WorkerStatus
|
||||||
{
|
{
|
||||||
|
public DateTime LastUpdate { get; set; }
|
||||||
public string Cid { get; set; } = string.Empty;
|
public string Cid { get; set; } = string.Empty;
|
||||||
public string EncodedCid { get; set; } = string.Empty;
|
public string EncodedCid { get; set; } = string.Empty;
|
||||||
public int FailureCounter { get; set; } = 0;
|
public int FailureCounter { get; set; } = 0;
|
||||||
|
@ -21,6 +21,7 @@ namespace AutoClient.Modes.FolderStore
|
|||||||
if (!File.Exists(FilePath))
|
if (!File.Exists(FilePath))
|
||||||
{
|
{
|
||||||
State = new T();
|
State = new T();
|
||||||
|
OnNewState(State);
|
||||||
SaveState();
|
SaveState();
|
||||||
}
|
}
|
||||||
var text = File.ReadAllText(FilePath);
|
var text = File.ReadAllText(FilePath);
|
||||||
@ -37,6 +38,10 @@ namespace AutoClient.Modes.FolderStore
|
|||||||
protected string FilePath { get; }
|
protected string FilePath { get; }
|
||||||
protected T State { get; private set; } = default!;
|
protected T State { get; private set; } = default!;
|
||||||
|
|
||||||
|
protected virtual void OnNewState(T newState)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
protected void SaveState()
|
protected void SaveState()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
Loading…
x
Reference in New Issue
Block a user