diff --git a/Wabbajack.Lib/Downloaders/HTTPDownloader.cs b/Wabbajack.Lib/Downloaders/HTTPDownloader.cs index 78dbd700..b554b7a7 100644 --- a/Wabbajack.Lib/Downloaders/HTTPDownloader.cs +++ b/Wabbajack.Lib/Downloaders/HTTPDownloader.cs @@ -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; diff --git a/Wabbajack.Lib/NexusApi/NexusApi.cs b/Wabbajack.Lib/NexusApi/NexusApi.cs index 4e500dd7..5f3986b8 100644 --- a/Wabbajack.Lib/NexusApi/NexusApi.cs +++ b/Wabbajack.Lib/NexusApi/NexusApi.cs @@ -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 Get(string url, Wabbajack.Lib.Http.Client? client = null) + public async Task Get(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(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; } } diff --git a/Wabbajack.Lib/WebAutomation/CefSharpWrapper.cs b/Wabbajack.Lib/WebAutomation/CefSharpWrapper.cs index c40d2b58..1782e14f 100644 --- a/Wabbajack.Lib/WebAutomation/CefSharpWrapper.cs +++ b/Wabbajack.Lib/WebAutomation/CefSharpWrapper.cs @@ -172,7 +172,6 @@ namespace Wabbajack.Lib.WebAutomation public TaskCompletionSource _tcs = new TaskCompletionSource(); private bool _quickMode; private CancellationToken? _cancelationToken; - private TimeSpan _downloadTimeout; public Task TaskResult => _tcs.Task; public ReroutingDownloadHandler(CefSharpWrapper wrapper, AbsolutePath path, bool quickMode, CancellationToken? token) diff --git a/Wabbajack.Server/Controllers/ListsStatus.cs b/Wabbajack.Server/Controllers/ListsStatus.cs index 36cd833e..96ff153f 100644 --- a/Wabbajack.Server/Controllers/ListsStatus.cs +++ b/Wabbajack.Server/Controllers/ListsStatus.cs @@ -168,7 +168,9 @@ namespace Wabbajack.BuildServer.Controllers [ResponseCache(Duration = 60 * 5)] public async Task 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(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)) diff --git a/Wabbajack.Server/Services/AbstractService.cs b/Wabbajack.Server/Services/AbstractService.cs index 8e91b7eb..f0c78ada 100644 --- a/Wabbajack.Server/Services/AbstractService.cs +++ b/Wabbajack.Server/Services/AbstractService.cs @@ -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(); diff --git a/Wabbajack.Server/Services/ListValidator.cs b/Wabbajack.Server/Services/ListValidator.cs index 7ef8f3a5..6b6197c7 100644 --- a/Wabbajack.Server/Services/ListValidator.cs +++ b/Wabbajack.Server/Services/ListValidator.cs @@ -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 ValidationInfo = new ConcurrentDictionary(); + public ConcurrentDictionary ValidationInfo = new(); public ListValidator(ILogger 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 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}"); diff --git a/Wabbajack.Server/Services/NexusKeyMaintainance.cs b/Wabbajack.Server/Services/NexusKeyMaintainance.cs index bb35fe60..32e9c28e 100644 --- a/Wabbajack.Server/Services/NexusKeyMaintainance.cs +++ b/Wabbajack.Server/Services/NexusKeyMaintainance.cs @@ -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 Execute()