some backend fixes

This commit is contained in:
Timothy Baldridge 2021-01-09 14:46:46 -07:00
parent 019bd9282b
commit 756113d77d
7 changed files with 43 additions and 26 deletions

View File

@ -154,7 +154,7 @@ TOP:
catch (Exception ex)
{
if (readThisCycle == 0)
throw ex;
throw;
if (totalRead < contentSize)
{
@ -169,7 +169,7 @@ TOP:
response = await client.SendAsync(msg);
goto TOP;
}
throw ex;
throw;
}
break;

View File

@ -20,7 +20,7 @@ namespace Wabbajack.Lib.NexusApi
{
private static readonly string API_KEY_CACHE_FILE = "nexus.key_cache";
public Wabbajack.Lib.Http.Client HttpClient { get; } = new Wabbajack.Lib.Http.Client();
public Http.Client HttpClient { get; } = new();
#region Authentication
@ -254,7 +254,7 @@ namespace Wabbajack.Lib.NexusApi
return new NexusApiClient(apiKey);
}
public async Task<T> Get<T>(string url, Wabbajack.Lib.Http.Client? client = null)
public async Task<T> Get<T>(string url, Http.Client? client = null)
{
client ??= HttpClient;
int retries = 0;
@ -269,7 +269,6 @@ namespace Wabbajack.Lib.NexusApi
throw new HttpException(response);
}
await using var stream = await response.Content.ReadAsStreamAsync();
return stream.FromJson<T>(genericReader:true);
}
@ -283,7 +282,7 @@ namespace Wabbajack.Lib.NexusApi
}
catch (Exception e)
{
Utils.Log(e.ToString());
Utils.Log($"Nexus call failed `{url}`: " + e);
throw;
}
}

View File

@ -172,7 +172,6 @@ namespace Wabbajack.Lib.WebAutomation
public TaskCompletionSource<long> _tcs = new TaskCompletionSource<long>();
private bool _quickMode;
private CancellationToken? _cancelationToken;
private TimeSpan _downloadTimeout;
public Task<long> TaskResult => _tcs.Task;
public ReroutingDownloadHandler(CefSharpWrapper wrapper, AbsolutePath path, bool quickMode, CancellationToken? token)

View File

@ -168,7 +168,9 @@ namespace Wabbajack.BuildServer.Controllers
[ResponseCache(Duration = 60 * 5)]
public async Task<IActionResult> HandleGetListJson(string Name)
{
return Ok((await DetailedStatus(Name)).ToJson());
var lst = await DetailedStatus(Name);
if (lst == null) return NotFound();
return Ok(lst.ToJson());
}
private async Task<DetailedStatus> DetailedStatus(string Name)
@ -176,6 +178,10 @@ namespace Wabbajack.BuildServer.Controllers
var results = _validator.Summaries
.Select(d => d.Detailed)
.FirstOrDefault(d => d.MachineName == Name);
if (results == null)
return null;
results!.Archives.Do(itm =>
{
if (string.IsNullOrWhiteSpace(itm.Archive.Name))

View File

@ -4,6 +4,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Logging;
using Wabbajack.BuildServer;
using Wabbajack.Common;
namespace Wabbajack.Server.Services
{
@ -65,6 +66,7 @@ namespace Wabbajack.Server.Services
try
{
_logger.LogInformation($"Running: {GetType().Name}");
ActiveWorkStatus = Array.Empty<(String, DateTime)>();
LastStart = DateTime.UtcNow;
await Execute();
LastEnd = DateTime.UtcNow;
@ -72,6 +74,7 @@ namespace Wabbajack.Server.Services
catch (Exception ex)
{
_logger.LogError(ex, "Running Service Loop");
Utils.Log($"Error in service {this.GetType()} : {ex}");
}
var token = await _quickSync.GetToken<TP>();

View File

@ -25,7 +25,7 @@ namespace Wabbajack.Server.Services
public IEnumerable<(ModListSummary Summary, DetailedStatus Detailed)> Summaries => ValidationInfo.Values.Select(e => (e.Summary, e.Detailed));
public ConcurrentDictionary<string, (ModListSummary Summary, DetailedStatus Detailed, TimeSpan ValidationTime)> ValidationInfo = new ConcurrentDictionary<string, (ModListSummary Summary, DetailedStatus Detailed, TimeSpan ValidationTime)>();
public ConcurrentDictionary<string, (ModListSummary Summary, DetailedStatus Detailed, TimeSpan ValidationTime)> ValidationInfo = new();
public ListValidator(ILogger<ListValidator> logger, AppSettings settings, SqlService sql, DiscordWebHook discord, NexusKeyMaintainance nexus, ArchiveMaintainer archives, QuickSync quickSync)
@ -57,14 +57,14 @@ namespace Wabbajack.Server.Services
var listArchives = await _sql.ModListArchives(metadata.Links.MachineURL);
var archives = await listArchives.PMap(queue, async archive =>
{
ReportStarting(archive.State.PrimaryKeyString);
if (timer.Elapsed > Delay)
{
return (archive, ArchiveStatus.InValid);
}
try
{
ReportStarting(archive.State.PrimaryKeyString);
if (timer.Elapsed > Delay)
{
return (archive, ArchiveStatus.InValid);
}
var (_, result) = await ValidateArchive(data, archive);
if (result == ArchiveStatus.InValid)
{
@ -334,7 +334,7 @@ namespace Wabbajack.Server.Services
}
}
private AsyncLock _lock = new AsyncLock();
private AsyncLock _lock = new();
public async Task<ArchiveStatus> FastNexusModStats(NexusDownloader.State ns)
{
@ -344,7 +344,7 @@ namespace Wabbajack.Server.Services
if (mod == null || files == null)
{
// Aquire the lock
// Acquire the lock
using var lck = await _lock.WaitAsync();
// Check again
@ -354,11 +354,12 @@ namespace Wabbajack.Server.Services
if (mod == null || files == null)
{
NexusApiClient nexusClient = await _nexus.GetClient();
var queryTime = DateTime.UtcNow;
try
{
NexusApiClient nexusClient = await _nexus.GetClient();
var queryTime = DateTime.UtcNow;
if (mod == null)
{
_logger.Log(LogLevel.Information, $"Found missing Nexus mod info {ns.Game} {ns.ModID}");

View File

@ -25,18 +25,27 @@ namespace Wabbajack.Server.Services
var keys = await _sql.GetNexusApiKeysWithCounts(1500);
foreach (var key in keys.Where(k => k.Key != _selfKey))
{
var client = new TrackingClient(_sql, key);
if (!await client.IsPremium())
try
{
_logger.LogWarning($"Purging non premium key");
await _sql.DeleteNexusAPIKey(key.Key);
continue;
var client = new TrackingClient(_sql, key);
if (!await client.IsPremium())
{
_logger.LogWarning($"Purging non premium key");
await _sql.DeleteNexusAPIKey(key.Key);
continue;
}
return client;
}
catch (Exception ex)
{
Utils.Log($"Error getting tracking client: {ex}");
}
return client;
}
return await NexusApiClient.Get();
var bclient = await NexusApiClient.Get();
await bclient.GetUserStatus();
return bclient;
}
public override async Task<int> Execute()