2
0
mirror of synced 2025-01-26 00:08:57 +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;
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;

View File

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