mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 12:59:39 -07:00
parent
adeeb7824d
commit
e9937884ad
4 changed files with 101 additions and 25 deletions
|
@ -39,9 +39,6 @@
|
|||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="RestSharp, Version=105.2.3.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>..\packages\RestSharp.105.2.3\lib\net452\RestSharp.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="IApiRequest.cs" />
|
||||
|
|
|
@ -62,7 +62,13 @@ namespace PlexRequests.Api
|
|||
request.AddUrlSegment("imdbid", imdbid);
|
||||
request.AddUrlSegment("title", title);
|
||||
|
||||
var obj = Api.ExecuteJson<JObject>(request, baseUrl);
|
||||
var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] {
|
||||
TimeSpan.FromSeconds (2),
|
||||
TimeSpan.FromSeconds(5),
|
||||
TimeSpan.FromSeconds(10)
|
||||
}, (exception, timespan) => Log.Error (exception, "Exception when calling AddMovie for CP, Retrying {0}", timespan));
|
||||
|
||||
var obj = (JObject)policy.Execute( () => Api.ExecuteJson<JObject>(request, baseUrl));
|
||||
Log.Trace("CP movie Add result count {0}", obj.Count);
|
||||
|
||||
if (obj.Count > 0)
|
||||
|
@ -99,8 +105,13 @@ namespace PlexRequests.Api
|
|||
};
|
||||
|
||||
request.AddUrlSegment("apikey", apiKey);
|
||||
var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] {
|
||||
TimeSpan.FromSeconds (2),
|
||||
TimeSpan.FromSeconds(5),
|
||||
TimeSpan.FromSeconds(10)
|
||||
}, (exception, timespan) => Log.Error (exception, "Exception when calling GetStatus for CP, Retrying {0}", timespan));
|
||||
|
||||
return Api.Execute<CouchPotatoStatus>(request,url);
|
||||
return (CouchPotatoStatus)policy.Execute( () => Api.Execute<CouchPotatoStatus>(request,url));
|
||||
}
|
||||
|
||||
public CouchPotatoProfiles GetProfiles(Uri url, string apiKey)
|
||||
|
@ -114,7 +125,13 @@ namespace PlexRequests.Api
|
|||
|
||||
request.AddUrlSegment("apikey", apiKey);
|
||||
|
||||
return Api.Execute<CouchPotatoProfiles>(request, url);
|
||||
var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] {
|
||||
TimeSpan.FromSeconds (2),
|
||||
TimeSpan.FromSeconds(5),
|
||||
TimeSpan.FromSeconds(10)
|
||||
}, (exception, timespan) => Log.Error (exception, "Exception when calling GetProfiles for CP, Retrying {0}", timespan));
|
||||
|
||||
return (CouchPotatoProfiles)policy.Execute( () => Api.Execute<CouchPotatoProfiles>(request,url));
|
||||
}
|
||||
|
||||
public CouchPotatoMovies GetMovies(Uri baseUrl, string apiKey, string[] status)
|
||||
|
@ -128,7 +145,13 @@ namespace PlexRequests.Api
|
|||
request.AddUrlSegment("status", string.Join(",", status));
|
||||
try
|
||||
{
|
||||
return Api.Execute<CouchPotatoMovies>(request, baseUrl);
|
||||
var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] {
|
||||
TimeSpan.FromSeconds (5),
|
||||
TimeSpan.FromSeconds(10),
|
||||
TimeSpan.FromSeconds(30)
|
||||
}, (exception, timespan) => Log.Error (exception, "Exception when calling GetMovies for CP, Retrying {0}", timespan));
|
||||
|
||||
return (CouchPotatoMovies)policy.Execute( () => Api.Execute<CouchPotatoMovies>(request,baseUrl));
|
||||
}
|
||||
catch (Exception e) // Request error is already logged in the ApiRequest class
|
||||
{
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
using Polly;
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -82,9 +83,14 @@ namespace PlexRequests.Api
|
|||
request.AddQueryParameter("initial", quality);
|
||||
}
|
||||
|
||||
Log.Trace("Entering `Execute<SickRageTvAdd>`");
|
||||
var obj = Api.Execute<SickRageTvAdd>(request, baseUrl);
|
||||
Log.Trace("Exiting `Execute<SickRageTvAdd>`");
|
||||
var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] {
|
||||
TimeSpan.FromSeconds (2),
|
||||
TimeSpan.FromSeconds(5),
|
||||
TimeSpan.FromSeconds(10)
|
||||
}, (exception, timespan) => Log.Error (exception, "Exception when calling AddSeries for SR, Retrying {0}", timespan));
|
||||
|
||||
|
||||
var obj = policy.Execute( () => Api.Execute<SickRageTvAdd>(request, baseUrl));
|
||||
Log.Trace("obj Result:");
|
||||
Log.Trace(obj.DumpJson());
|
||||
|
||||
|
@ -95,7 +101,6 @@ namespace PlexRequests.Api
|
|||
|
||||
var seasonIncrement = 0;
|
||||
var seasonList = new SickRageSeasonList();
|
||||
Log.Trace("while (seasonIncrement < seasonCount) where seasonCount = {0}", seasonCount);
|
||||
try
|
||||
{
|
||||
while (seasonIncrement < seasonCount)
|
||||
|
@ -132,7 +137,8 @@ namespace PlexRequests.Api
|
|||
foreach (var s in seasons)
|
||||
{
|
||||
Log.Trace("Adding season {0}", s);
|
||||
var result = await AddSeason(tvdbId, s, apiKey, baseUrl);
|
||||
|
||||
var result = await AddSeason(tvdbId, s, apiKey, baseUrl);
|
||||
Log.Trace("SickRage adding season results: ");
|
||||
Log.Trace(result.DumpJson());
|
||||
}
|
||||
|
@ -157,8 +163,17 @@ namespace PlexRequests.Api
|
|||
Method = Method.GET
|
||||
};
|
||||
|
||||
|
||||
var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] {
|
||||
TimeSpan.FromSeconds (2),
|
||||
TimeSpan.FromSeconds(5),
|
||||
TimeSpan.FromSeconds(10)
|
||||
}, (exception, timespan) => Log.Error (exception, "Exception when calling Ping for SR, Retrying {0}", timespan));
|
||||
|
||||
|
||||
|
||||
request.AddUrlSegment("apiKey", apiKey);
|
||||
var obj = Api.ExecuteJson<SickRagePing>(request, baseUrl);
|
||||
var obj = policy.Execute( () => Api.ExecuteJson<SickRagePing>(request, baseUrl));
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
@ -176,9 +191,14 @@ namespace PlexRequests.Api
|
|||
|
||||
try
|
||||
{
|
||||
Log.Trace("Entering `ExecuteJson<SickRageSeasonList>`");
|
||||
var obj = Api.ExecuteJson<SickRageSeasonList>(request, baseUrl);
|
||||
Log.Trace("Exited `ExecuteJson<SickRageSeasonList>`");
|
||||
var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] {
|
||||
TimeSpan.FromSeconds (2),
|
||||
TimeSpan.FromSeconds(5),
|
||||
TimeSpan.FromSeconds(10)
|
||||
}, (exception, timespan) => Log.Error (exception, "Exception when calling VerifyShowHasLoaded for SR, Retrying {0}", timespan));
|
||||
|
||||
|
||||
var obj = policy.Execute( () => Api.ExecuteJson<SickRageSeasonList>(request, baseUrl));
|
||||
return obj;
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -203,10 +223,16 @@ namespace PlexRequests.Api
|
|||
await Task.Run(() => Thread.Sleep(2000));
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
Log.Trace("Entering `Execute<SickRageTvAdd>` in a new `Task<T>`");
|
||||
var result = Api.Execute<SickRageTvAdd>(request, baseUrl);
|
||||
|
||||
Log.Trace("Exiting `Execute<SickRageTvAdd>` and yeilding `Task<T>` result");
|
||||
var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] {
|
||||
TimeSpan.FromSeconds (2),
|
||||
TimeSpan.FromSeconds(5),
|
||||
TimeSpan.FromSeconds(10)
|
||||
}, (exception, timespan) => Log.Error (exception, "Exception when calling AddSeason for SR, Retrying {0}", timespan));
|
||||
|
||||
|
||||
var result = policy.Execute(() => Api.Execute<SickRageTvAdd>(request, baseUrl));
|
||||
|
||||
return result;
|
||||
}).ConfigureAwait(false);
|
||||
}
|
||||
|
@ -225,7 +251,15 @@ namespace PlexRequests.Api
|
|||
{
|
||||
try
|
||||
{
|
||||
return Api.Execute<SickrageShows>(request, baseUrl);
|
||||
var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] {
|
||||
TimeSpan.FromSeconds (5),
|
||||
TimeSpan.FromSeconds(10),
|
||||
TimeSpan.FromSeconds(30)
|
||||
}, (exception, timespan) => Log.Error (exception, "Exception when calling GetShows for SR, Retrying {0}", timespan));
|
||||
|
||||
|
||||
return policy.Execute(() => Api.Execute<SickrageShows>(request, baseUrl));
|
||||
|
||||
}
|
||||
catch (ApiRequestException)
|
||||
{
|
||||
|
|
|
@ -56,8 +56,13 @@ namespace PlexRequests.Api
|
|||
var request = new RestRequest { Resource = "/api/profile", Method = Method.GET };
|
||||
|
||||
request.AddHeader("X-Api-Key", apiKey);
|
||||
var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] {
|
||||
TimeSpan.FromSeconds (2),
|
||||
TimeSpan.FromSeconds(5),
|
||||
TimeSpan.FromSeconds(10)
|
||||
}, (exception, timespan) => Log.Error (exception, "Exception when calling GetProfiles for Sonarr, Retrying {0}", timespan));
|
||||
|
||||
var obj = Api.ExecuteJson<List<SonarrProfile>>(request, baseUrl);
|
||||
var obj = policy.Execute(() => Api.ExecuteJson<List<SonarrProfile>>(request, baseUrl));
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
@ -102,7 +107,13 @@ namespace PlexRequests.Api
|
|||
SonarrAddSeries result;
|
||||
try
|
||||
{
|
||||
result = Api.ExecuteJson<SonarrAddSeries>(request, baseUrl);
|
||||
var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] {
|
||||
TimeSpan.FromSeconds (2),
|
||||
TimeSpan.FromSeconds(5),
|
||||
TimeSpan.FromSeconds(10)
|
||||
}, (exception, timespan) => Log.Error (exception, "Exception when calling AddSeries for Sonarr, Retrying {0}", timespan));
|
||||
|
||||
result = policy.Execute(() => Api.ExecuteJson<SonarrAddSeries>(request, baseUrl));
|
||||
}
|
||||
catch (JsonSerializationException jse)
|
||||
{
|
||||
|
@ -121,7 +132,13 @@ namespace PlexRequests.Api
|
|||
var request = new RestRequest { Resource = "/api/system/status", Method = Method.GET };
|
||||
request.AddHeader("X-Api-Key", apiKey);
|
||||
|
||||
var obj = Api.ExecuteJson<SystemStatus>(request, baseUrl);
|
||||
var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] {
|
||||
TimeSpan.FromSeconds (2),
|
||||
TimeSpan.FromSeconds(5),
|
||||
TimeSpan.FromSeconds(10)
|
||||
}, (exception, timespan) => Log.Error (exception, "Exception when calling SystemStatus for Sonarr, Retrying {0}", timespan));
|
||||
|
||||
var obj = policy.Execute(() => Api.ExecuteJson<SystemStatus>(request, baseUrl));
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
@ -132,9 +149,14 @@ namespace PlexRequests.Api
|
|||
request.AddHeader("X-Api-Key", apiKey);
|
||||
try
|
||||
{
|
||||
var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] {
|
||||
TimeSpan.FromSeconds (5),
|
||||
TimeSpan.FromSeconds(10),
|
||||
TimeSpan.FromSeconds(30)
|
||||
}, (exception, timespan) => Log.Error (exception, "Exception when calling GetSeries for Sonarr, Retrying {0}", timespan));
|
||||
|
||||
return Api.Execute<List<Series>>(request, baseUrl);
|
||||
}
|
||||
return policy.Execute(() => Api.ExecuteJson<List<Series>>(request, baseUrl));
|
||||
}
|
||||
catch (ApiRequestException)
|
||||
{
|
||||
Log.Error("There has been an API exception when getting the Sonarr Series");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue