Implement dynamic request throttle configuration; update HttpClient initialization
This commit is contained in:
3
.vscode/mcp.example.json
vendored
3
.vscode/mcp.example.json
vendored
@@ -10,7 +10,8 @@
|
|||||||
],
|
],
|
||||||
"env": {
|
"env": {
|
||||||
"USERNAME": "mail@address.com",
|
"USERNAME": "mail@address.com",
|
||||||
"PASSWORD": "sup3rsecur3"
|
"PASSWORD": "sup3rsecur3",
|
||||||
|
"REQUEST_THROTTLE_MS": "500"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,23 @@ namespace FsMcp;
|
|||||||
|
|
||||||
internal sealed class FoodsharingApiClient
|
internal sealed class FoodsharingApiClient
|
||||||
{
|
{
|
||||||
|
private const string RequestThrottleMsEnvVar = "REQUEST_THROTTLE_MS";
|
||||||
|
|
||||||
private readonly SemaphoreSlim _loginLock = new(1, 1);
|
private readonly SemaphoreSlim _loginLock = new(1, 1);
|
||||||
|
|
||||||
public HttpClient HttpClient { get; } = new(new RequestThrottleHandler(TimeSpan.FromMilliseconds(200)));
|
public HttpClient HttpClient { get; } = new(new RequestThrottleHandler(TimeSpan.FromMilliseconds(GetRequestThrottleMs())));
|
||||||
|
|
||||||
|
private static int GetRequestThrottleMs()
|
||||||
|
{
|
||||||
|
string? configuredValue = Environment.GetEnvironmentVariable(RequestThrottleMsEnvVar);
|
||||||
|
|
||||||
|
if (int.TryParse(configuredValue, out int throttleMs) && throttleMs >= 0)
|
||||||
|
{
|
||||||
|
return throttleMs;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 500;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task EnsureLoginAsync()
|
public async Task EnsureLoginAsync()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user