mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Version 2.0.6.0 - Don't die on 503s, retry
This commit is contained in:
parent
28b11b1c7f
commit
aab9ccd694
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace Wabbajack.Lib.Exceptions
|
||||
namespace Wabbajack.Common.Exceptions
|
||||
{
|
||||
public class HttpException : Exception
|
||||
{
|
@ -6,6 +6,7 @@ using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using HtmlAgilityPack;
|
||||
using Wabbajack.Common.Exceptions;
|
||||
|
||||
namespace Wabbajack.Common.Http
|
||||
{
|
||||
@ -83,13 +84,22 @@ namespace Wabbajack.Common.Http
|
||||
if (response.IsSuccessStatusCode) return response;
|
||||
|
||||
if (errorsAsExceptions)
|
||||
throw new HttpRequestException(
|
||||
$"Http Exception {response.StatusCode} - {response.ReasonPhrase} - {msg.RequestUri}");
|
||||
throw new HttpException(response);
|
||||
|
||||
return response;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (ex is HttpRequestException) throw;
|
||||
if (ex is HttpException http)
|
||||
{
|
||||
if (http.Code != 503) throw;
|
||||
|
||||
var ms = Utils.NextRandom(100, 1000);
|
||||
Utils.Log($"Got a 503 from {msg.RequestUri} retrying in {ms}ms");
|
||||
|
||||
await Task.Delay(ms);
|
||||
goto TOP;
|
||||
}
|
||||
if (retries > Consts.MaxHTTPRetries) throw;
|
||||
|
||||
retries++;
|
||||
|
@ -1203,5 +1203,11 @@ namespace Wabbajack.Common
|
||||
if (lst.Count > 0 && lst.Count != size)
|
||||
yield return lst;
|
||||
}
|
||||
|
||||
private static Random _random = new Random();
|
||||
public static int NextRandom(int min, int max)
|
||||
{
|
||||
return _random.Next(min, max);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,13 +2,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Common.Exceptions;
|
||||
using Wabbajack.Common.Serialization.Json;
|
||||
using Wabbajack.Lib.Downloaders;
|
||||
using Wabbajack.Lib.Exceptions;
|
||||
|
||||
namespace Wabbajack.Lib
|
||||
{
|
||||
|
@ -2,6 +2,7 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
@ -120,16 +121,15 @@ namespace Wabbajack.Lib.Downloaders
|
||||
|
||||
public override async Task<bool> Download(Archive a, AbsolutePath destination)
|
||||
{
|
||||
await using var stream = await ResolveDownloadStream(a);
|
||||
using var stream = await ResolveDownloadStream(a);
|
||||
if (stream == null) return false;
|
||||
await using (var file = destination.Create())
|
||||
{
|
||||
await stream.CopyToAsync(file);
|
||||
}
|
||||
await using var fromStream = await stream.Content.ReadAsStreamAsync();
|
||||
await using var toStream = destination.Create();
|
||||
await fromStream.CopyToAsync(toStream);
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task<Stream?> ResolveDownloadStream(Archive a)
|
||||
private async Task<HttpResponseMessage?> ResolveDownloadStream(Archive a)
|
||||
{
|
||||
TOP:
|
||||
string url;
|
||||
@ -181,7 +181,7 @@ namespace Wabbajack.Lib.Downloaders
|
||||
if (a.Size != 0 && headerContentSize != 0 && a.Size != headerContentSize)
|
||||
return null;
|
||||
|
||||
return await streamResult.Content.ReadAsStreamAsync();
|
||||
return streamResult;
|
||||
}
|
||||
|
||||
// Sometimes LL hands back a json object telling us to wait until a certain time
|
||||
@ -211,7 +211,7 @@ namespace Wabbajack.Lib.Downloaders
|
||||
if (stream == null)
|
||||
return false;
|
||||
|
||||
stream.Close();
|
||||
stream.Dispose();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,8 @@
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Common.Exceptions;
|
||||
using Wabbajack.Common.Serialization.Json;
|
||||
using Wabbajack.Lib.Exceptions;
|
||||
using Wabbajack.Lib.Validation;
|
||||
|
||||
namespace Wabbajack.Lib.Downloaders
|
||||
|
@ -5,11 +5,10 @@ using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading.Tasks;
|
||||
using AngleSharp.Css;
|
||||
using Newtonsoft.Json;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Common.Exceptions;
|
||||
using Wabbajack.Common.Serialization.Json;
|
||||
using Wabbajack.Lib.Exceptions;
|
||||
using Wabbajack.Lib.Validation;
|
||||
|
||||
namespace Wabbajack.Lib.Downloaders
|
||||
|
@ -2,13 +2,11 @@
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.IO.MemoryMappedFiles;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Common.Exceptions;
|
||||
using Wabbajack.Common.Serialization.Json;
|
||||
using Wabbajack.Lib.AuthorApi;
|
||||
using Wabbajack.Lib.Downloaders.UrlDownloaders;
|
||||
using Wabbajack.Lib.Exceptions;
|
||||
using Wabbajack.Lib.Validation;
|
||||
|
||||
namespace Wabbajack.Lib.Downloaders
|
||||
|
@ -5,16 +5,11 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Reflection;
|
||||
using System.Security.Authentication;
|
||||
using System.Threading.Tasks;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Lib.Downloaders;
|
||||
using WebSocketSharp;
|
||||
using static Wabbajack.Lib.NexusApi.NexusApiUtils;
|
||||
using System.Threading;
|
||||
using Wabbajack.Lib.Exceptions;
|
||||
using Wabbajack.Lib.WebAutomation;
|
||||
|
||||
namespace Wabbajack.Lib.NexusApi
|
||||
|
@ -1,19 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Dapper;
|
||||
using Wabbajack.BuildServer;
|
||||
using Wabbajack.BuildServer.Test;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Common.Exceptions;
|
||||
using Wabbajack.Lib;
|
||||
using Wabbajack.Lib.Downloaders;
|
||||
using Wabbajack.Lib.Exceptions;
|
||||
using Wabbajack.Lib.ModListRegistry;
|
||||
using Wabbajack.Lib.NexusApi;
|
||||
using Wabbajack.Server.DataLayer;
|
||||
using Wabbajack.Server.DTOs;
|
||||
using Wabbajack.Server.Services;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
Loading…
Reference in New Issue
Block a user