mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-14 02:26:55 -07:00
Added the ability to refresh out backend metadata (#2078)
We now can refresh the Plex Metadata in our database. For example if the Plex Agent for TV Shows is TheMovieDb, we will use that and populate the IMDB Id and TheTvDb Id's so we can accuratly match and search things. Also improved the Job settings page so we can Test CRON's and we also validate them.
This commit is contained in:
parent
d1ba626f46
commit
47f66978f0
29 changed files with 667 additions and 46 deletions
|
@ -1,4 +1,7 @@
|
|||
using System.IO;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -6,6 +9,7 @@ using System.Xml.Serialization;
|
|||
using Newtonsoft.Json;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Ombi.Helpers;
|
||||
using Polly;
|
||||
|
||||
namespace Ombi.Api
|
||||
{
|
||||
|
@ -36,6 +40,30 @@ namespace Ombi.Api
|
|||
if (!httpResponseMessage.IsSuccessStatusCode)
|
||||
{
|
||||
LogError(request, httpResponseMessage);
|
||||
if (request.Retry)
|
||||
{
|
||||
|
||||
var result = Policy
|
||||
.Handle<HttpRequestException>()
|
||||
.OrResult<HttpResponseMessage>(r => request.StatusCodeToRetry.Contains(r.StatusCode))
|
||||
.WaitAndRetryAsync(new[]
|
||||
{
|
||||
TimeSpan.FromSeconds(10),
|
||||
}, (exception, timeSpan, context) =>
|
||||
{
|
||||
|
||||
Logger.LogError(LoggingEvents.Api,
|
||||
$"Retrying RequestUri: {request.FullUri} Because we got Status Code: {exception?.Result?.StatusCode}");
|
||||
});
|
||||
|
||||
httpResponseMessage = await result.ExecuteAsync(async () =>
|
||||
{
|
||||
using (var req = await httpRequestMessage.Clone())
|
||||
{
|
||||
return await _client.SendAsync(req);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// do something with the response
|
||||
|
|
45
src/Ombi.Api/HttpRequestExtnesions.cs
Normal file
45
src/Ombi.Api/HttpRequestExtnesions.cs
Normal file
|
@ -0,0 +1,45 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ombi.Api
|
||||
{
|
||||
public static class HttpRequestExtnesions
|
||||
{
|
||||
public static async Task<HttpRequestMessage> Clone(this HttpRequestMessage request)
|
||||
{
|
||||
var clone = new HttpRequestMessage(request.Method, request.RequestUri)
|
||||
{
|
||||
Content = await request.Content.Clone(),
|
||||
Version = request.Version
|
||||
};
|
||||
foreach (KeyValuePair<string, object> prop in request.Properties)
|
||||
{
|
||||
clone.Properties.Add(prop);
|
||||
}
|
||||
foreach (KeyValuePair<string, IEnumerable<string>> header in request.Headers)
|
||||
{
|
||||
clone.Headers.TryAddWithoutValidation(header.Key, header.Value);
|
||||
}
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
public static async Task<HttpContent> Clone(this HttpContent content)
|
||||
{
|
||||
if (content == null) return null;
|
||||
|
||||
var ms = new MemoryStream();
|
||||
await content.CopyToAsync(ms);
|
||||
ms.Position = 0;
|
||||
|
||||
var clone = new StreamContent(ms);
|
||||
foreach (KeyValuePair<string, IEnumerable<string>> header in content.Headers)
|
||||
{
|
||||
clone.Headers.Add(header.Key, header.Value);
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@
|
|||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.0.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
||||
<PackageReference Include="Polly" Version="5.8.0" />
|
||||
<PackageReference Include="System.Xml.XmlSerializer" Version="4.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
|
||||
|
@ -25,6 +26,9 @@ namespace Ombi.Api
|
|||
public string BaseUrl { get; }
|
||||
public HttpMethod HttpMethod { get; }
|
||||
|
||||
public bool Retry { get; set; }
|
||||
public List<HttpStatusCode> StatusCodeToRetry { get; set; } = new List<HttpStatusCode>();
|
||||
|
||||
public Action<string> OnBeforeDeserialization { get; set; }
|
||||
|
||||
private string FullUrl
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue