Added a TMDB Rate limiter for the newsletter

This commit is contained in:
tidusjar 2017-02-14 21:56:48 +00:00
commit febdaa0a15

View file

@ -31,6 +31,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading;
using NLog; using NLog;
using Ombi.Api; using Ombi.Api;
using Ombi.Api.Interfaces; using Ombi.Api.Interfaces;
@ -41,6 +42,7 @@ using Ombi.Services.Jobs.Templates;
using Ombi.Store.Models; using Ombi.Store.Models;
using Ombi.Store.Models.Emby; using Ombi.Store.Models.Emby;
using Ombi.Store.Repository; using Ombi.Store.Repository;
using TMDbLib.Objects.Exceptions;
using EmbyMediaType = Ombi.Store.Models.Plex.EmbyMediaType; using EmbyMediaType = Ombi.Store.Models.Plex.EmbyMediaType;
namespace Ombi.Services.Jobs.RecentlyAddedNewsletter namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
@ -195,6 +197,9 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
sb.Append( sb.Append(
"<table border=\"0\" cellpadding=\"0\" align=\"center\" cellspacing=\"0\" style=\"border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;\" width=\"100%\">"); "<table border=\"0\" cellpadding=\"0\" align=\"center\" cellspacing=\"0\" style=\"border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;\" width=\"100%\">");
foreach (var movie in orderedMovies) foreach (var movie in orderedMovies)
{
// We have a try within a try so we can catch the rate limit without ending the loop (finally block)
try
{ {
try try
{ {
@ -223,6 +228,13 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
AddParagraph(sb, info.Overview); AddParagraph(sb, info.Overview);
} }
catch (RequestLimitExceededException limit)
{
// We have hit a limit, we need to now wait.
Thread.Sleep(TimeSpan.FromSeconds(10));
Log.Info(limit);
}
}
catch (Exception e) catch (Exception e)
{ {
Log.Error(e); Log.Error(e);