Added a retry policy around the emby newsletter

pull/1334/head
Jamie.Rees 8 years ago
parent 59f3ce35f3
commit d0c994a925

@ -45,6 +45,7 @@ using Ombi.Store.Models.Emby;
using Ombi.Store.Repository;
using TMDbLib.Objects.Exceptions;
using EmbyMediaType = Ombi.Store.Models.Plex.EmbyMediaType;
using Polly;
namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
{
@ -121,14 +122,20 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
var info = new List<EmbyRecentlyAddedModel>();
foreach (var m in filteredMovies)
{
var i = Api.GetInformation(m.EmbyId, Ombi.Api.Models.Emby.EmbyMediaType.Movie,
embySettings.ApiKey, embySettings.AdministratorId, embySettings.FullUri);
info.Add(new EmbyRecentlyAddedModel
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) =>
Log.Error(exception, "Exception thrown when processing an emby movie for the newsletter, Retrying {0}", timespan));
var result = policy.Execute(() =>
{
EmbyInformation = i,
EmbyContent = m
var i = Api.GetInformation(m.EmbyId, Ombi.Api.Models.Emby.EmbyMediaType.Movie,
embySettings.ApiKey, embySettings.AdministratorId, embySettings.FullUri);
return new EmbyRecentlyAddedModel
{
EmbyInformation = i,
EmbyContent = m
};
});
info.Add(result);
}
GenerateMovieHtml(info, sb);
newsletter.MovieCount = info.Count;
@ -142,46 +149,49 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
var recentlyAddedModel = new List<EmbyRecentlyAddedModel>();
foreach (var embyEpisodes in filteredEp)
{
// Let's sleep, Emby can't keep up with us.
Thread.Sleep(1000);
try
{
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) =>
Log.Error(exception, "Exception thrown when processing an emby episode for the newsletter, Retrying {0}", timespan));
// Find related series item
var relatedSeries = series.FirstOrDefault(x => x.EmbyId == embyEpisodes.ParentId);
if (relatedSeries == null)
policy.Execute(() =>
{
continue;
}
// Find related series item
var relatedSeries = series.FirstOrDefault(x => x.EmbyId == embyEpisodes.ParentId);
// Get series information
var i = Api.GetInformation(relatedSeries.EmbyId, Ombi.Api.Models.Emby.EmbyMediaType.Series,
embySettings.ApiKey, embySettings.AdministratorId, embySettings.FullUri);
if (relatedSeries == null)
{
return;
}
Thread.Sleep(200);
var episodeInfo = Api.GetInformation(embyEpisodes.EmbyId,
Ombi.Api.Models.Emby.EmbyMediaType.Episode,
embySettings.ApiKey, embySettings.AdministratorId, embySettings.FullUri);
// Check if we already have this series
var existingSeries = recentlyAddedModel.FirstOrDefault(x =>
x.EmbyInformation.SeriesInformation.Id.Equals(i.SeriesInformation.Id,
StringComparison.CurrentCultureIgnoreCase));
// Get series information
var i = Api.GetInformation(relatedSeries.EmbyId, Ombi.Api.Models.Emby.EmbyMediaType.Series,
embySettings.ApiKey, embySettings.AdministratorId, embySettings.FullUri);
if (existingSeries != null)
{
existingSeries.EpisodeInformation.Add(episodeInfo.EpisodeInformation);
}
else
{
recentlyAddedModel.Add(new EmbyRecentlyAddedModel
Thread.Sleep(200);
var episodeInfo = Api.GetInformation(embyEpisodes.EmbyId,
Ombi.Api.Models.Emby.EmbyMediaType.Episode,
embySettings.ApiKey, embySettings.AdministratorId, embySettings.FullUri);
// Check if we already have this series
var existingSeries = recentlyAddedModel.FirstOrDefault(x =>
x.EmbyInformation.SeriesInformation.Id.Equals(i.SeriesInformation.Id,
StringComparison.CurrentCultureIgnoreCase));
if (existingSeries != null)
{
EmbyInformation = i,
EpisodeInformation = new List<EmbyEpisodeInformation>() { episodeInfo.EpisodeInformation },
EmbyContent = relatedSeries
});
}
existingSeries.EpisodeInformation.Add(episodeInfo.EpisodeInformation);
}
else
{
recentlyAddedModel.Add(new EmbyRecentlyAddedModel
{
EmbyInformation = i,
EpisodeInformation = new List<EmbyEpisodeInformation>() { episodeInfo.EpisodeInformation },
EmbyContent = relatedSeries
});
}
});
}
catch (JsonReaderException)
@ -197,13 +207,21 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
{
foreach (var t in filteredSeries)
{
var i = Api.GetInformation(t.EmbyId, Ombi.Api.Models.Emby.EmbyMediaType.Series,
embySettings.ApiKey, embySettings.AdministratorId, embySettings.FullUri);
var item = new EmbyRecentlyAddedModel
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) =>
Log.Error(exception, "Exception thrown when processing an emby series for the newsletter, Retrying {0}", timespan));
var item = policy.Execute(() =>
{
EmbyContent = t,
EmbyInformation = i,
};
var i = Api.GetInformation(t.EmbyId, Ombi.Api.Models.Emby.EmbyMediaType.Series,
embySettings.ApiKey, embySettings.AdministratorId, embySettings.FullUri);
var model = new EmbyRecentlyAddedModel
{
EmbyContent = t,
EmbyInformation = i,
};
return model;
});
info.Add(item);
}
}

@ -48,6 +48,7 @@
<HintPath>..\packages\NLog.4.3.6\lib\net45\NLog.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Polly, Version=4.3.0.0, Culture=neutral, PublicKeyToken=c8a3ffc3f8f825cc" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Security" />

Loading…
Cancel
Save