mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Rework the nexus api limit code a bit
This commit is contained in:
parent
ff6743b468
commit
1212d35290
@ -153,6 +153,14 @@ namespace Wabbajack.Lib.NexusApi
|
||||
return await Get<UserStatus>(url);
|
||||
}
|
||||
|
||||
public async Task<(int, int)> GetRemainingApiCalls()
|
||||
{
|
||||
var url = "https://api.nexusmods.com/v1/users/validate.json";
|
||||
using var response = await HttpClient.GetAsync(url);
|
||||
return (int.Parse(response.Headers.GetValues("X-RL-Daily-Remaining").First()),
|
||||
int.Parse(response.Headers.GetValues("X-RL-Hourly-Remaining").First()));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Rate Tracking
|
||||
|
@ -26,12 +26,16 @@ namespace Wabbajack.Server.Services
|
||||
public override async Task<int> Execute()
|
||||
{
|
||||
_nexusClient ??= await NexusApiClient.Get();
|
||||
await _nexusClient.GetUserStatus();
|
||||
int count = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
bool ignoreNexus = _nexusClient.HourlyRemaining < 25;
|
||||
var (daily, hourly) = await _nexusClient.GetRemainingApiCalls();
|
||||
bool ignoreNexus = hourly < 25;
|
||||
if (ignoreNexus)
|
||||
_logger.LogWarning($"Ignoring Nexus Downloads due to low hourly api limit (Daily: {_nexusClient.DailyRemaining}, Hourly:{_nexusClient.HourlyRemaining})");
|
||||
else
|
||||
_logger.LogInformation($"Looking for any download (Daily: {_nexusClient.DailyRemaining}, Hourly:{_nexusClient.HourlyRemaining})");
|
||||
|
||||
var nextDownload = await _sql.GetNextPendingDownload(ignoreNexus);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user