Skip to content

Commit 278b6c9

Browse files
committed
Sets autoclient long webcall timeout
1 parent fe75609 commit 278b6c9

File tree

6 files changed

+58
-13
lines changed

6 files changed

+58
-13
lines changed

ProjectPlugins/CodexClient/CodexNodeFactory.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ public CodexNodeFactory(ILog log, IFileManager fileManager, CodexHooksFactory ho
2222
this.processControlFactory = processControlFactory;
2323
}
2424

25+
public CodexNodeFactory(ILog log, HttpFactory httpFactory, string dataDir)
26+
: this(log, new FileManager(log, dataDir), new CodexHooksFactory(), httpFactory, new DoNothingProcessControlFactory())
27+
{
28+
}
29+
2530
public CodexNodeFactory(ILog log, string dataDir)
26-
: this(log, new FileManager(log, dataDir), new CodexHooksFactory(), new HttpFactory(log), new DoNothingProcessControlFactory())
31+
: this(log, new HttpFactory(log), dataDir)
2732
{
2833
}
2934

Tools/AutoClient/App.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using AutoClient.Modes.FolderStore;
22
using CodexClient;
33
using Logging;
4+
using WebUtils;
45

56
namespace AutoClient
67
{
@@ -30,7 +31,9 @@ public App(Configuration config)
3031
FolderWorkDispatcher = null!;
3132
}
3233

33-
CodexNodeFactory = new CodexNodeFactory(log: Log, dataDir: Config.DataPath);
34+
var httpFactory = new HttpFactory(Log, new AutoClientWebTimeSet());
35+
36+
CodexNodeFactory = new CodexNodeFactory(log: Log, httpFactory: httpFactory, dataDir: Config.DataPath);
3437
}
3538

3639
public Configuration Config { get; }
@@ -50,4 +53,25 @@ private IFileGenerator CreateGenerator()
5053
return new ImageGenerator(Log);
5154
}
5255
}
56+
57+
public class AutoClientWebTimeSet : IWebCallTimeSet
58+
{
59+
public TimeSpan HttpCallTimeout()
60+
{
61+
return TimeSpan.FromMinutes(30.0);
62+
}
63+
64+
public TimeSpan HttpRetryTimeout()
65+
{
66+
return HttpCallTimeout() * 2.2;
67+
}
68+
69+
/// <summary>
70+
/// After a failed HTTP call, wait this long before trying again.
71+
/// </summary>
72+
public TimeSpan HttpCallRetryDelay()
73+
{
74+
return TimeSpan.FromMinutes(1.0);
75+
}
76+
}
5377
}

Tools/AutoClient/Modes/FolderStore/FileStatus.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ public FileStatus(App app, string folder, string filePath, PurchaseInfo purchase
1212
this.purchaseInfo = purchaseInfo;
1313
}
1414

15+
protected override void OnNewState(WorkerStatus newState)
16+
{
17+
newState.LastUpdate = DateTime.MinValue;
18+
}
19+
1520
public bool IsBusy()
1621
{
1722
if (!State.Purchases.Any()) return false;
@@ -48,7 +53,7 @@ public bool IsCurrentlyFailed()
4853
return mostRecent.Expiry.HasValue;
4954
}
5055

51-
protected WorkerPurchase? GetMostRecent()
56+
public WorkerPurchase? GetMostRecent()
5257
{
5358
if (!State.Purchases.Any()) return null;
5459
var maxCreated = State.Purchases.Max(p => p.Created);

Tools/AutoClient/Modes/FolderStore/FileWorker.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ public interface IWorkEventHandler
1111
void OnPurchaseStarted();
1212
}
1313

14-
public class FileWorker : FileStatus
14+
public class FileWorker
1515
{
1616
private readonly App app;
1717
private readonly CodexWrapper node;
1818
private readonly ILog log;
1919
private readonly PurchaseInfo purchaseInfo;
2020
private readonly string sourceFilename;
2121
private readonly IWorkEventHandler eventHandler;
22+
private readonly FileStatus status;
2223

2324
public FileWorker(App app, CodexWrapper node, PurchaseInfo purchaseInfo, string folder, FileIndex fileIndex, IWorkEventHandler eventHandler)
24-
: base(app, folder, fileIndex.File + ".json", purchaseInfo)
2525
{
2626
this.app = app;
2727
this.node = node;
@@ -30,18 +30,17 @@ public FileWorker(App app, CodexWrapper node, PurchaseInfo purchaseInfo, string
3030
sourceFilename = fileIndex.File;
3131
if (sourceFilename.ToLowerInvariant().EndsWith(".json")) throw new Exception("Not an era file.");
3232
this.eventHandler = eventHandler;
33-
}
3433

35-
protected override void OnNewState(WorkerStatus newState)
36-
{
37-
newState.LastUpdate = DateTime.MinValue;
34+
status = new FileStatus(app, folder, fileIndex.File, purchaseInfo);
3835
}
3936

37+
public bool IsBusy => status.IsBusy();
38+
4039
public void Update()
4140
{
4241
try
4342
{
44-
if (IsCurrentlyRunning() && UpdatedRecently()) return;
43+
if (status.IsCurrentlyRunning() && UpdatedRecently()) return;
4544

4645
Log($"Updating for '{sourceFilename}'...");
4746
EnsureRecentPurchase();
@@ -271,6 +270,18 @@ private void Log(string msg)
271270
log.Log(msg);
272271
}
273272

273+
private WorkerStatus State => status.State;
274+
275+
private void SaveState()
276+
{
277+
status.SaveState();
278+
}
279+
280+
private WorkerPurchase? GetMostRecent()
281+
{
282+
return status.GetMostRecent();
283+
}
284+
274285
private string GetFileTag(FileIndex filename)
275286
{
276287
return $"({filename.Index.ToString("00000")}) ";

Tools/AutoClient/Modes/FolderStore/JsonBacked.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ private void LoadState()
3636

3737
protected string Folder { get; }
3838
protected string FilePath { get; }
39-
protected T State { get; private set; } = default!;
39+
public T State { get; private set; } = default!;
4040

4141
protected virtual void OnNewState(T newState)
4242
{
4343
}
4444

45-
protected void SaveState()
45+
public void SaveState()
4646
{
4747
try
4848
{

Tools/AutoClient/Modes/FolderStoreMode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private FileWorker ProcessWorkItem(CodexWrapper instance)
6262
var file = app.FolderWorkDispatcher.GetFileToCheck();
6363
var worker = new FileWorker(app, instance, purchaseInfo, folder, file, this);
6464
worker.Update();
65-
if (worker.IsBusy()) app.FolderWorkDispatcher.WorkerIsBusy();
65+
if (worker.IsBusy) app.FolderWorkDispatcher.WorkerIsBusy();
6666
return worker;
6767
}
6868

0 commit comments

Comments
 (0)