mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-21 13:53:19 -07:00
Added a retry policy around the emby newsletter
This commit is contained in:
parent
59f3ce35f3
commit
d0c994a925
2 changed files with 65 additions and 46 deletions
|
@ -45,6 +45,7 @@ using Ombi.Store.Models.Emby;
|
||||||
using Ombi.Store.Repository;
|
using Ombi.Store.Repository;
|
||||||
using TMDbLib.Objects.Exceptions;
|
using TMDbLib.Objects.Exceptions;
|
||||||
using EmbyMediaType = Ombi.Store.Models.Plex.EmbyMediaType;
|
using EmbyMediaType = Ombi.Store.Models.Plex.EmbyMediaType;
|
||||||
|
using Polly;
|
||||||
|
|
||||||
namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
||||||
{
|
{
|
||||||
|
@ -121,14 +122,20 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
||||||
var info = new List<EmbyRecentlyAddedModel>();
|
var info = new List<EmbyRecentlyAddedModel>();
|
||||||
foreach (var m in filteredMovies)
|
foreach (var m in filteredMovies)
|
||||||
{
|
{
|
||||||
|
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) =>
|
||||||
var i = Api.GetInformation(m.EmbyId, Ombi.Api.Models.Emby.EmbyMediaType.Movie,
|
Log.Error(exception, "Exception thrown when processing an emby movie for the newsletter, Retrying {0}", timespan));
|
||||||
embySettings.ApiKey, embySettings.AdministratorId, embySettings.FullUri);
|
var result = policy.Execute(() =>
|
||||||
info.Add(new EmbyRecentlyAddedModel
|
|
||||||
{
|
{
|
||||||
EmbyInformation = i,
|
var i = Api.GetInformation(m.EmbyId, Ombi.Api.Models.Emby.EmbyMediaType.Movie,
|
||||||
EmbyContent = m
|
embySettings.ApiKey, embySettings.AdministratorId, embySettings.FullUri);
|
||||||
|
|
||||||
|
return new EmbyRecentlyAddedModel
|
||||||
|
{
|
||||||
|
EmbyInformation = i,
|
||||||
|
EmbyContent = m
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
info.Add(result);
|
||||||
}
|
}
|
||||||
GenerateMovieHtml(info, sb);
|
GenerateMovieHtml(info, sb);
|
||||||
newsletter.MovieCount = info.Count;
|
newsletter.MovieCount = info.Count;
|
||||||
|
@ -142,46 +149,49 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
||||||
var recentlyAddedModel = new List<EmbyRecentlyAddedModel>();
|
var recentlyAddedModel = new List<EmbyRecentlyAddedModel>();
|
||||||
foreach (var embyEpisodes in filteredEp)
|
foreach (var embyEpisodes in filteredEp)
|
||||||
{
|
{
|
||||||
// Let's sleep, Emby can't keep up with us.
|
|
||||||
Thread.Sleep(1000);
|
|
||||||
try
|
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
|
policy.Execute(() =>
|
||||||
var relatedSeries = series.FirstOrDefault(x => x.EmbyId == embyEpisodes.ParentId);
|
|
||||||
|
|
||||||
if (relatedSeries == null)
|
|
||||||
{
|
{
|
||||||
continue;
|
// Find related series item
|
||||||
}
|
var relatedSeries = series.FirstOrDefault(x => x.EmbyId == embyEpisodes.ParentId);
|
||||||
|
|
||||||
// Get series information
|
if (relatedSeries == null)
|
||||||
var i = Api.GetInformation(relatedSeries.EmbyId, Ombi.Api.Models.Emby.EmbyMediaType.Series,
|
|
||||||
embySettings.ApiKey, embySettings.AdministratorId, embySettings.FullUri);
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
existingSeries.EpisodeInformation.Add(episodeInfo.EpisodeInformation);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
recentlyAddedModel.Add(new EmbyRecentlyAddedModel
|
|
||||||
{
|
{
|
||||||
EmbyInformation = i,
|
return;
|
||||||
EpisodeInformation = new List<EmbyEpisodeInformation>() { episodeInfo.EpisodeInformation },
|
}
|
||||||
EmbyContent = relatedSeries
|
|
||||||
});
|
// Get series information
|
||||||
}
|
var i = Api.GetInformation(relatedSeries.EmbyId, Ombi.Api.Models.Emby.EmbyMediaType.Series,
|
||||||
|
embySettings.ApiKey, embySettings.AdministratorId, embySettings.FullUri);
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
existingSeries.EpisodeInformation.Add(episodeInfo.EpisodeInformation);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
recentlyAddedModel.Add(new EmbyRecentlyAddedModel
|
||||||
|
{
|
||||||
|
EmbyInformation = i,
|
||||||
|
EpisodeInformation = new List<EmbyEpisodeInformation>() { episodeInfo.EpisodeInformation },
|
||||||
|
EmbyContent = relatedSeries
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (JsonReaderException)
|
catch (JsonReaderException)
|
||||||
|
@ -197,13 +207,21 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
||||||
{
|
{
|
||||||
foreach (var t in filteredSeries)
|
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,
|
var i = Api.GetInformation(t.EmbyId, Ombi.Api.Models.Emby.EmbyMediaType.Series,
|
||||||
EmbyInformation = i,
|
embySettings.ApiKey, embySettings.AdministratorId, embySettings.FullUri);
|
||||||
};
|
var model = new EmbyRecentlyAddedModel
|
||||||
|
{
|
||||||
|
EmbyContent = t,
|
||||||
|
EmbyInformation = i,
|
||||||
|
};
|
||||||
|
return model;
|
||||||
|
});
|
||||||
info.Add(item);
|
info.Add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
<HintPath>..\packages\NLog.4.3.6\lib\net45\NLog.dll</HintPath>
|
<HintPath>..\packages\NLog.4.3.6\lib\net45\NLog.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Polly, Version=4.3.0.0, Culture=neutral, PublicKeyToken=c8a3ffc3f8f825cc" />
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Security" />
|
<Reference Include="System.Security" />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue