Added the Radarr cacher #865

pull/1425/head
tidusjar 7 years ago
parent d5ec429893
commit 1133f02d07

@ -165,10 +165,11 @@ namespace Ombi.Core.Models.Requests
public async Task<IEnumerable<T>> GetAllAsync(int count, int position) public async Task<IEnumerable<T>> GetAllAsync(int count, int position)
{ {
var blobs = await Repo.GetAllAsync(count, position).ConfigureAwait(false); var blobs = await Repo.GetAllAsync().ConfigureAwait(false);
var retVal = new List<T>(); var retVal = new List<T>();
foreach (var b in blobs.Where(x => x.Type == RequestType)) foreach (var b in blobs.Where(x => x.Type == RequestType).Skip(position).Take(count))
{ {
if (b == null) if (b == null)
continue; continue;

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Ombi.Helpers
{
public static class CacheKeys
{
public const string RadarrCacher = nameof(RadarrCacher);
}
}

@ -6,5 +6,6 @@ namespace Ombi.Helpers
{ {
public static EventId ApiException => new EventId(1000); public static EventId ApiException => new EventId(1000);
public static EventId CacherException => new EventId(2000); public static EventId CacherException => new EventId(2000);
public static EventId RadarrCacherException => new EventId(2001);
} }
} }

@ -6,15 +6,18 @@ namespace Ombi.Schedule
{ {
public class JobSetup : IJobSetup public class JobSetup : IJobSetup
{ {
public JobSetup(IPlexContentCacher cacher) public JobSetup(IPlexContentCacher cacher, IRadarrCacher radarrCache)
{ {
Cacher = cacher; PlexCacher = cacher;
RadarrCacher = radarrCache;
} }
private IPlexContentCacher Cacher { get; } private IPlexContentCacher PlexCacher { get; }
private IRadarrCacher RadarrCacher { get; }
public void Setup() public void Setup()
{ {
RecurringJob.AddOrUpdate(() => Cacher.CacheContent(), Cron.Hourly); RecurringJob.AddOrUpdate(() => PlexCacher.CacheContent(), Cron.Hourly);
RecurringJob.AddOrUpdate(() => RadarrCacher.Start(), Cron.MonthInterval(61));
} }
} }
} }

@ -0,0 +1,9 @@
using System.Threading.Tasks;
namespace Ombi.Schedule.Jobs
{
public interface IRadarrCacher
{
Task Start();
}
}

@ -0,0 +1,65 @@
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
using Ombi.Api.Radarr;
using Ombi.Core.Settings;
using Ombi.Helpers;
using Ombi.Settings.Settings.Models.External;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace Ombi.Schedule.Jobs
{
public class RadarrCacher : IRadarrCacher
{
public RadarrCacher(ISettingsService<RadarrSettings> radarr, IRadarrApi api, IMemoryCache cache, ILogger<RadarrCacher> logger)
{
RadarrSettings = radarr;
Api = api;
Cache = cache;
Log = logger;
}
private ISettingsService<RadarrSettings> RadarrSettings { get; }
private IRadarrApi Api { get; }
private IMemoryCache Cache { get; }
private ILogger<RadarrCacher> Log { get; }
public async Task Start()
{
var settings = RadarrSettings.GetSettings();
if (settings.Enabled)
{
try
{
var movies = await Api.GetMovies(settings.ApiKey, settings.FullUri);
if (movies != null)
{
var movieIds = new List<int>();
foreach (var m in movies)
{
if (m.tmdbId > 0)
{
movieIds.Add(m.tmdbId);
}
else
{
Log.LogError("TMDBId is not > 0 for movie {0}", m.title);
}
}
Cache.Set<IEnumerable<int>>(CacheKeys.RadarrCacher, movieIds);
}
}
catch (System.Exception ex)
{
Log.LogError(LoggingEvents.RadarrCacherException, ex, "Failed caching queued items from Radarr");
}
finally
{
// Record job run
}
}
}
}
}

@ -14,6 +14,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Ombi.Api.Plex\Ombi.Api.Plex.csproj" /> <ProjectReference Include="..\Ombi.Api.Plex\Ombi.Api.Plex.csproj" />
<ProjectReference Include="..\Ombi.Api.Radarr\Ombi.Api.Radarr.csproj" />
<ProjectReference Include="..\Ombi.Core\Ombi.Core.csproj" /> <ProjectReference Include="..\Ombi.Core\Ombi.Core.csproj" />
<ProjectReference Include="..\Ombi.Settings\Ombi.Settings.csproj" /> <ProjectReference Include="..\Ombi.Settings\Ombi.Settings.csproj" />
</ItemGroup> </ItemGroup>

@ -12,7 +12,6 @@ namespace Ombi.Store.Repository
RequestBlobs Get(int id); RequestBlobs Get(int id);
IEnumerable<RequestBlobs> GetAll(); IEnumerable<RequestBlobs> GetAll();
Task<IEnumerable<RequestBlobs>> GetAllAsync(); Task<IEnumerable<RequestBlobs>> GetAllAsync();
Task<IEnumerable<RequestBlobs>> GetAllAsync(int count, int position);
Task<RequestBlobs> GetAsync(int id); Task<RequestBlobs> GetAsync(int id);
RequestBlobs Insert(RequestBlobs entity); RequestBlobs Insert(RequestBlobs entity);
Task<RequestBlobs> InsertAsync(RequestBlobs entity); Task<RequestBlobs> InsertAsync(RequestBlobs entity);

@ -62,18 +62,6 @@ namespace Ombi.Store.Repository
//}, 5); //}, 5);
//return item; //return item;
} }
public async Task<IEnumerable<RequestBlobs>> GetAllAsync(int count, int position)
{
//var key = "GetAll";
//var item = await Cache.GetOrSetAsync(key, async () =>
//{
var page = await Db.Requests.ToListAsync().ConfigureAwait(false);
return page.Skip(position).Take(count);
//}, 5);
//return item;
}
public RequestBlobs Get(int id) public RequestBlobs Get(int id)
{ {

@ -60,6 +60,7 @@ namespace Ombi
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
// Add framework services. // Add framework services.
services.AddMemoryCache();
services.AddMvc(); services.AddMvc();
services.AddOmbiMappingProfile(); services.AddOmbiMappingProfile();
services.AddAutoMapper(expression => services.AddAutoMapper(expression =>

@ -58,6 +58,8 @@ var paths = {
'./node_modules/bootstrap/dist/js/bootstrap.js', './node_modules/bootstrap/dist/js/bootstrap.js',
'./node_modules/tether/dist/js/tether.js', './node_modules/tether/dist/js/tether.js',
'./node_modules/angular2-jwt/angular2-jwt.js', './node_modules/angular2-jwt/angular2-jwt.js',
'./node_modules/dragula/dist/dragula.js'
], ],
dest: './lib/' dest: './lib/'
@ -75,7 +77,7 @@ var paths = {
'./node_modules/primeng/resources/primeng.css', './node_modules/primeng/resources/primeng.css',
'./node_modules/tether/dist/css/tether.css', './node_modules/tether/dist/css/tether.css',
'./node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css', './node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css',
'./node_modules/dragula/dist/dragula.css' './node_modules/dragula/dist/dragula.js'
], ],
dest: './css/lib/' dest: './css/lib/'
}, },

File diff suppressed because it is too large Load Diff

@ -1,3 +1,3 @@
<div *ngIf="request"> <div *ngIf="request" style="background-color:black; color:white;">
{{request.title}} {{request.title}}
</div> </div>

@ -1,39 +1,50 @@
 
<style>
.landing-box {
height: 150px;
background: #333333 !important;
border-radius: 2%;
display: flex;
justify-content: center;
flex-direction: column;
text-align: center;
box-shadow: 5px 3px 5px black;
}
</style>
<div *ngIf="tvRequests"> <div *ngIf="tvRequests">
<div class="col-md-4"> <div class="col-md-4">
<md-card> <div class="landing-box">
<md-card-title>Title</md-card-title> <md-card-title>Title</md-card-title>
<div [dragula]='"requests"' [dragulaModel]="tvRequests.new"> <div [dragula]='"requests-bag"' [dragulaModel]="tvRequests.new">
<br /> <br />
<br /> <br />
<request-card *ngFor="let item of tvRequests.new" [request]="item" [attr.data.id]="item.id"></request-card> <request-card *ngFor="let item of tvRequests.new" [request]="item" ></request-card>
</div> </div>
</md-card> </div>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<md-card> <div class="landing-box">
<md-card-title>Title</md-card-title>
<div [dragula]='"requests"' [dragulaModel]="tvRequests.approved"> <div [dragula]='"requests-bag"' [dragulaModel]="tvRequests.approved">
<br /> <br />
<br /> <br />
<request-card *ngFor="let item of tvRequests.approved" [request]="item" [attr.data.id]="item.id"></request-card> <request-card *ngFor="let item of tvRequests.approved" [request]="item"></request-card>
</div> </div>
</md-card> </div>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<md-card> <div class="landing-box">
<md-card-title>Title</md-card-title> <md-card-title>Title</md-card-title>
<div style="border: dashed"> <div style="border: dashed">
<div [dragula]='"requests"' [dragulaModel]="tvRequests.available"> <div [dragula]='"requests-bag"' [dragulaModel]="tvRequests.available">
<br /> <br />
<br /> <br />
<request-card *ngFor="let item of tvRequests.available" [request]="item" [attr.data.id]="item.id"></request-card> <request-card *ngFor="let item of tvRequests.available" [request]="item"></request-card>
</div> </div>
</div> </div>
</md-card> </div>
</div> </div>
</div> </div>

@ -10,13 +10,7 @@ import { ITvRequestModel, IMovieRequestModel, IRequestGrid } from '../interfaces
export class RequestGridComponent implements OnInit { export class RequestGridComponent implements OnInit {
constructor(private dragulaService: DragulaService, private requestService: RequestService) { constructor(private dragulaService: DragulaService, private requestService: RequestService) {
this.dragulaService.setOptions('requests', {
removeOnSpill: false,
});
this.dragulaService.drop.subscribe((value: any) => { this.dragulaService.drop.subscribe((value: any) => {
}); });
} }

@ -24,7 +24,6 @@ export class ServiceHelpers {
// We'd also dig deeper into the error to get a better message // We'd also dig deeper into the error to get a better message
let errMsg = (error.message) ? error.message : let errMsg = (error.message) ? error.message :
error.status ? `${error.status} - ${error.statusText}` : 'Server error'; error.status ? `${error.status} - ${error.statusText}` : 'Server error';
console.error(errMsg); // log to console instead
return Observable.throw(errMsg); return Observable.throw(errMsg);
} }
@ -51,7 +50,6 @@ export class ServiceAuthHelpers {
// We'd also dig deeper into the error to get a better message // We'd also dig deeper into the error to get a better message
let errMsg = (error.message) ? error.message : let errMsg = (error.message) ? error.message :
error.status ? `${error.status} - ${error.statusText}` : 'Server error'; error.status ? `${error.status} - ${error.statusText}` : 'Server error';
console.error(errMsg); // log to console instead
return Observable.throw(errMsg); return Observable.throw(errMsg);
} }

@ -1,7 +1,6 @@
 
<settings-menu></settings-menu> <settings-menu></settings-menu>
<div *ngIf="settings"> <div *ngIf="settings">
<form class="form-horizontal" method="POST" id="mainForm">
<fieldset> <fieldset>
<legend>Radarr Settings</legend> <legend>Radarr Settings</legend>
@ -100,5 +99,4 @@
</div> </div>
</div> </div>
</fieldset> </fieldset>
</form>
</div> </div>

@ -1,7 +1,6 @@
 
<settings-menu></settings-menu> <settings-menu></settings-menu>
<div *ngIf="settings"> <div *ngIf="settings">
<form class="form-horizontal" method="POST" id="mainForm">
<fieldset> <fieldset>
<legend>Sonarr Settings</legend> <legend>Sonarr Settings</legend>
@ -100,5 +99,4 @@
</div> </div>
</div> </div>
</fieldset> </fieldset>
</form>
</div> </div>

Loading…
Cancel
Save