2
0
mirror of synced 2025-02-05 05:04:17 +00:00

Slow down logging when waiting for requests to start.

This commit is contained in:
benbierens 2024-11-27 11:35:56 +01:00
parent 23622245f0
commit a40d5d77d7
No known key found for this signature in database
GPG Key ID: 877D2C2E09A22F3A
2 changed files with 24 additions and 0 deletions

View File

@ -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;

View File

@ -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