Added the option to run the content cacher from the settings page, it will no longer get triggered when we press save.

This commit is contained in:
tidusjar 2017-10-21 21:01:33 +01:00
parent 03f7aba47e
commit 2f8e96ed87
8 changed files with 112 additions and 76 deletions

View file

@ -29,4 +29,12 @@ export class JobService extends ServiceAuthHelpers {
public runEmbyImporter(): Observable<boolean> { public runEmbyImporter(): Observable<boolean> {
return this.http.post(`${this.url}embyUserImporter/`, { headers: this.headers }).map(this.extractData); return this.http.post(`${this.url}embyUserImporter/`, { headers: this.headers }).map(this.extractData);
} }
public runPlexCacher(): Observable<boolean> {
return this.http.post(`${this.url}plexcontentcacher/`, { headers: this.headers }).map(this.extractData);
}
public runEmbyCacher(): Observable<boolean> {
return this.http.post(`${this.url}embycontentcacher/`, { headers: this.headers }).map(this.extractData);
}
} }

View file

@ -14,7 +14,7 @@
</div> </div>
</div> </div>
<div class="col-md-2 col-md-push-7"> <div class="col-md-2 col-md-push-7">
<button type="submit" (click)="addTab()" class="btn btn-success-outline">Add Server</button> <button type="button" (click)="addTab()" class="btn btn-success-outline">Add Server</button>
</div> </div>
</div> </div>
@ -25,7 +25,7 @@
<br /> <br />
<br /> <br />
<div class="col-md-2" style="float: right;"> <div class="col-md-2" style="float: right;">
<button type="submit" (click)="removeServer(server)" class="btn btn-danger-outline">Remove Server</button> <button type="button" (click)="removeServer(server)" class="btn btn-danger-outline">Remove Server</button>
</div> </div>
<br /> <br />
<br /> <br />
@ -57,17 +57,6 @@
</div> </div>
</div> </div>
<!--<div class="form-group">
<div class="checkbox">
<input type="checkbox" id="EnableTvEpisodeSearching" [(ngModel)]="server.enableEpisodeSearching" ng-checked="server.enableEpisodeSearching">
<label for="EnableTvEpisodeSearching">Enable Episode Searching</label>
</div>
</div>-->
<div class="form-group"> <div class="form-group">
<label for="authToken" class="control-label">Emby Api Key</label> <label for="authToken" class="control-label">Emby Api Key</label>
<div class=""> <div class="">
@ -76,7 +65,7 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<div> <div>
<button id="testEmby" type="submit" (click)="test(server)" class="btn btn-primary-outline">Test Connectivity <div id="spinner"></div></button> <button id="testEmby" type="button" (click)="test(server)" class="btn btn-primary-outline">Test Connectivity <div id="spinner"></div></button>
</div> </div>
</div> </div>
</div> </div>
@ -84,12 +73,19 @@
</ngb-tab> </ngb-tab>
</div> </div>
</ngb-tabset> </ngb-tabset>
<div class="col-md-12"> <div class="col-md-1">
<div class="form-group"> <div class="form-group">
<div> <div>
<button (click)="save()" type="submit" id="save" class="btn btn-primary-outline">Submit</button> <button (click)="save()" type="submit" id="save" class="btn btn-primary-outline">Submit</button>
</div> </div>
</div> </div>
</div> </div>
<div class="col-md-1">
<div class="form-group">
<div>
<button (click)="runCacher()" type="button" id="save" class="btn btn-primary-outline">Manually Run Cacher</button>
</div>
</div>
</div>
</fieldset> </fieldset>
</div> </div>

View file

@ -1,9 +1,7 @@
import { Component, OnInit } from "@angular/core"; import { Component, OnInit } from "@angular/core";
import { IEmbyServer, IEmbySettings } from "../../interfaces"; import { IEmbyServer, IEmbySettings } from "../../interfaces";
import { TesterService } from "../../services"; import { JobService, NotificationService, SettingsService, TesterService } from "../../services";
import { NotificationService } from "../../services";
import { SettingsService } from "../../services";
@Component({ @Component({
templateUrl: "./emby.component.html", templateUrl: "./emby.component.html",
@ -14,7 +12,8 @@ export class EmbyComponent implements OnInit {
constructor(private settingsService: SettingsService, constructor(private settingsService: SettingsService,
private notificationService: NotificationService, private notificationService: NotificationService,
private testerService: TesterService) { } private testerService: TesterService,
private jobService: JobService) { }
public ngOnInit() { public ngOnInit() {
this.settingsService.getEmby().subscribe(x => this.settings = x); this.settingsService.getEmby().subscribe(x => this.settings = x);
@ -63,4 +62,12 @@ export class EmbyComponent implements OnInit {
} }
}); });
} }
public runCacher(): void {
this.jobService.runEmbyCacher().subscribe(x => {
if(x) {
this.notificationService.success("Running","Triggered the Emby Content Cacher");
}
});
}
} }

View file

@ -18,7 +18,7 @@
</div> </div>
</div> </div>
<div class="col-md-2 col-md-push-7"> <div class="col-md-2 col-md-push-7">
<button type="submit" (click)="addTab()" class="btn btn-success-outline">Add Server</button> <button type="button" (click)="addTab()" class="btn btn-success-outline">Add Server</button>
</div> </div>
</div> </div>
@ -30,7 +30,7 @@
<br /> <br />
<br /> <br />
<div class="col-md-2 " style="float: right;"> <div class="col-md-2 " style="float: right;">
<button type="submit" (click)="removeServer(server)" class="btn btn-danger-outline">Remove Server</button> <button type="button" (click)="removeServer(server)" class="btn btn-danger-outline">Remove Server</button>
</div> </div>
<br /> <br />
<br /> <br />
@ -158,7 +158,7 @@
<div class="form-group"> <div class="form-group">
<div> <div>
<button id="testPlex" type="submit" (click)="testPlex(server)" class="btn btn-primary-outline"> <button id="testPlex" type="button" (click)="testPlex(server)" class="btn btn-primary-outline">
Test Connectivity Test Connectivity
<div id="spinner"></div> <div id="spinner"></div>
</button> </button>
@ -171,12 +171,19 @@
</ngb-tab> </ngb-tab>
</div> </div>
</ngb-tabset> </ngb-tabset>
<div class="col-md-3"> <div class="col-md-1">
<div class="form-group"> <div class="form-group">
<div> <div>
<button (click)="save()" type="submit" id="save" class="btn btn-primary-outline">Submit</button> <button (click)="save()" type="submit" id="save" class="btn btn-primary-outline">Submit</button>
</div>
</div> </div>
</div> </div>
</div> <div class="col-md-1">
<div class="form-group">
<div>
<button (click)="runCacher()" type="button" id="save" class="btn btn-primary-outline">Manually Run Cacher</button>
</div>
</div>
</div>
</fieldset> </fieldset>
</div> </div>

View file

@ -5,10 +5,7 @@ import { Subject } from "rxjs/Subject";
import { IPlexServerResponse, IPlexServerViewModel } from "../../interfaces"; import { IPlexServerResponse, IPlexServerViewModel } from "../../interfaces";
import { IPlexLibrariesSettings, IPlexServer, IPlexSettings } from "../../interfaces"; import { IPlexLibrariesSettings, IPlexServer, IPlexSettings } from "../../interfaces";
import { PlexService } from "../../services"; import { JobService, NotificationService, PlexService, SettingsService, TesterService } from "../../services";
import { TesterService } from "../../services";
import { NotificationService } from "../../services";
import { SettingsService } from "../../services";
@Component({ @Component({
templateUrl: "./plex.component.html", templateUrl: "./plex.component.html",
@ -20,14 +17,15 @@ export class PlexComponent implements OnInit, OnDestroy {
public password: string; public password: string;
public serversButton = false; public serversButton = false;
private subscriptions = new Subject<void>();
public advanced = false; public advanced = false;
private subscriptions = new Subject<void>();
constructor(private settingsService: SettingsService, constructor(private settingsService: SettingsService,
private notificationService: NotificationService, private notificationService: NotificationService,
private plexService: PlexService, private plexService: PlexService,
private testerService: TesterService) { } private testerService: TesterService,
private jobService: JobService) { }
public ngOnInit() { public ngOnInit() {
this.settingsService.getPlex().subscribe(x => { this.settingsService.getPlex().subscribe(x => {
@ -40,7 +38,6 @@ export class PlexComponent implements OnInit, OnDestroy {
.takeUntil(this.subscriptions) .takeUntil(this.subscriptions)
.subscribe(x => { .subscribe(x => {
if (x.success) { if (x.success) {
debugger;
this.loadedServers = x; this.loadedServers = x;
this.serversButton = true; this.serversButton = true;
this.notificationService.success("Loaded", "Found the servers! Please select one!"); this.notificationService.success("Loaded", "Found the servers! Please select one!");
@ -121,6 +118,14 @@ export class PlexComponent implements OnInit, OnDestroy {
}); });
} }
public runCacher(): void {
this.jobService.runPlexCacher().subscribe(x => {
if(x) {
this.notificationService.success("Running","Triggered the Plex Content Cacher");
}
});
}
public ngOnDestroy() { public ngOnDestroy() {
this.subscriptions.next(); this.subscriptions.next();
this.subscriptions.complete(); this.subscriptions.complete();

View file

@ -68,24 +68,6 @@ namespace Ombi.Controllers.External
Name = "Server 1", Name = "Server 1",
} }
}; };
//var serverNumber = 0;
//foreach (var s in servers)
//{
// if (string.IsNullOrEmpty(s.LocalAddresses) || string.IsNullOrEmpty(s.Port))
// {
// continue;
// }
// settings.Servers.Add(new PlexServers
// {
// PlexAuthToken = result.user.authentication_token,
// Id = new Random().Next(),
// Ip = s.LocalAddresses.Split(new []{','}, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault(),
// MachineIdentifier = s.MachineIdentifier,
// Port = int.Parse(s.Port),
// Ssl = s.Scheme != "http",
// Name = $"Server{serverNumber++}"
// });
//}
await PlexSettings.SaveSettingsAsync(settings); await PlexSettings.SaveSettingsAsync(settings);
} }

View file

@ -6,6 +6,7 @@ using Microsoft.Extensions.Caching.Memory;
using Ombi.Api.Service; using Ombi.Api.Service;
using Ombi.Attributes; using Ombi.Attributes;
using Ombi.Helpers; using Ombi.Helpers;
using Ombi.Schedule.Jobs;
using Ombi.Schedule.Jobs.Emby; using Ombi.Schedule.Jobs.Emby;
using Ombi.Schedule.Jobs.Ombi; using Ombi.Schedule.Jobs.Ombi;
using Ombi.Schedule.Jobs.Plex; using Ombi.Schedule.Jobs.Plex;
@ -18,19 +19,28 @@ namespace Ombi.Controllers
public class JobController : Controller public class JobController : Controller
{ {
public JobController(IOmbiAutomaticUpdater updater, IPlexUserImporter userImporter, public JobController(IOmbiAutomaticUpdater updater, IPlexUserImporter userImporter,
IMemoryCache mem, IEmbyUserImporter embyImporter) IMemoryCache mem, IEmbyUserImporter embyImporter, IPlexContentCacher plexContentCacher,
IEmbyContentCacher embyContentCacher)
{ {
_updater = updater; _updater = updater;
_plexUserImporter = userImporter; _plexUserImporter = userImporter;
_embyUserImporter = embyImporter; _embyUserImporter = embyImporter;
_memCache = mem; _memCache = mem;
_plexContentCacher = plexContentCacher;
_embyContentCacher = embyContentCacher;
} }
private readonly IOmbiAutomaticUpdater _updater; private readonly IOmbiAutomaticUpdater _updater;
private readonly IPlexUserImporter _plexUserImporter; private readonly IPlexUserImporter _plexUserImporter;
private readonly IEmbyUserImporter _embyUserImporter; private readonly IEmbyUserImporter _embyUserImporter;
private readonly IMemoryCache _memCache; private readonly IMemoryCache _memCache;
private readonly IPlexContentCacher _plexContentCacher;
private readonly IEmbyContentCacher _embyContentCacher;
/// <summary>
/// Runs the update job
/// </summary>
/// <returns></returns>
[HttpPost("update")] [HttpPost("update")]
public bool ForceUpdate() public bool ForceUpdate()
{ {
@ -38,26 +48,29 @@ namespace Ombi.Controllers
return true; return true;
} }
/// <summary>
/// Checks for an update
/// </summary>
/// <returns></returns>
[HttpGet("update")] [HttpGet("update")]
public async Task<bool> CheckForUpdate() public async Task<bool> CheckForUpdate()
{ {
try try
{ {
var productArray = _updater.GetVersion();
var version = productArray[0];
var branch = productArray[1];
var updateAvailable = await _updater.UpdateAvailable(branch, version);
return updateAvailable;
var productArray = _updater.GetVersion();
var version = productArray[0];
var branch = productArray[1];
var updateAvailable = await _updater.UpdateAvailable(branch, version);
return updateAvailable;
} }
catch (Exception e) catch (Exception)
{ {
return false; return false;
} }
} }
[ApiExplorerSettings(IgnoreApi = true)]
[HttpGet("updateCached")] [HttpGet("updateCached")]
public async Task<bool> CheckForUpdateCached() public async Task<bool> CheckForUpdateCached()
{ {
@ -74,6 +87,10 @@ namespace Ombi.Controllers
return val; return val;
} }
/// <summary>
/// Runs the Plex User importer
/// </summary>
/// <returns></returns>
[HttpPost("plexuserimporter")] [HttpPost("plexuserimporter")]
public bool PlexUserImporter() public bool PlexUserImporter()
{ {
@ -81,11 +98,37 @@ namespace Ombi.Controllers
return true; return true;
} }
/// <summary>
/// Runs the Emby User importer
/// </summary>
/// <returns></returns>
[HttpPost("embyuserimporter")] [HttpPost("embyuserimporter")]
public bool EmbyUserImporter() public bool EmbyUserImporter()
{ {
BackgroundJob.Enqueue(() => _embyUserImporter.Start()); BackgroundJob.Enqueue(() => _embyUserImporter.Start());
return true; return true;
} }
/// <summary>
/// Runs the Plex Content Cacher
/// </summary>
/// <returns></returns>
[HttpPost("plexcontentcacher")]
public bool StartPlexContentCacher()
{
BackgroundJob.Enqueue(() => _plexContentCacher.CacheContent());
return true;
}
/// <summary>
/// Runs the Emby Content Cacher
/// </summary>
/// <returns></returns>
[HttpPost("embycontentcacher")]
public bool StartEmbyContentCacher()
{
BackgroundJob.Enqueue(() => _embyContentCacher.Start());
return true;
}
} }
} }

View file

@ -17,7 +17,6 @@ using Ombi.Core.Settings.Models;
using Ombi.Core.Settings.Models.External; using Ombi.Core.Settings.Models.External;
using Ombi.Helpers; using Ombi.Helpers;
using Ombi.Models; using Ombi.Models;
using Ombi.Schedule.Jobs;
using Ombi.Schedule.Jobs.Emby; using Ombi.Schedule.Jobs.Emby;
using Ombi.Schedule.Jobs.Radarr; using Ombi.Schedule.Jobs.Radarr;
using Ombi.Settings.Settings.Models; using Ombi.Settings.Settings.Models;
@ -44,14 +43,13 @@ namespace Ombi.Controllers
/// <param name="mapper">The mapper.</param> /// <param name="mapper">The mapper.</param>
/// <param name="templateRepo">The templateRepo.</param> /// <param name="templateRepo">The templateRepo.</param>
/// <param name="embyApi">The embyApi.</param> /// <param name="embyApi">The embyApi.</param>
/// <param name="cacher">The cacher.</param>
/// <param name="embyCacher">The embyCacher.</param> /// <param name="embyCacher">The embyCacher.</param>
/// <param name="radarrCacher">The radarrCacher.</param> /// <param name="radarrCacher">The radarrCacher.</param>
/// <param name="memCache">The memory cache.</param>
public SettingsController(ISettingsResolver resolver, public SettingsController(ISettingsResolver resolver,
IMapper mapper, IMapper mapper,
INotificationTemplatesRepository templateRepo, INotificationTemplatesRepository templateRepo,
IEmbyApi embyApi, IEmbyApi embyApi,
IPlexContentCacher cacher,
IEmbyContentCacher embyCacher, IEmbyContentCacher embyCacher,
IRadarrCacher radarrCacher, IRadarrCacher radarrCacher,
IMemoryCache memCache) IMemoryCache memCache)
@ -60,7 +58,6 @@ namespace Ombi.Controllers
Mapper = mapper; Mapper = mapper;
TemplateRepository = templateRepo; TemplateRepository = templateRepo;
_embyApi = embyApi; _embyApi = embyApi;
_plexContentCacher = cacher;
_embyContentCacher = embyCacher; _embyContentCacher = embyCacher;
_radarrCacher = radarrCacher; _radarrCacher = radarrCacher;
_cache = memCache; _cache = memCache;
@ -70,7 +67,6 @@ namespace Ombi.Controllers
private IMapper Mapper { get; } private IMapper Mapper { get; }
private INotificationTemplatesRepository TemplateRepository { get; } private INotificationTemplatesRepository TemplateRepository { get; }
private readonly IEmbyApi _embyApi; private readonly IEmbyApi _embyApi;
private readonly IPlexContentCacher _plexContentCacher;
private readonly IEmbyContentCacher _embyContentCacher; private readonly IEmbyContentCacher _embyContentCacher;
private readonly IRadarrCacher _radarrCacher; private readonly IRadarrCacher _radarrCacher;
private readonly IMemoryCache _cache; private readonly IMemoryCache _cache;
@ -145,10 +141,6 @@ namespace Ombi.Controllers
public async Task<bool> PlexSettings([FromBody]PlexSettings plex) public async Task<bool> PlexSettings([FromBody]PlexSettings plex)
{ {
var result = await Save(plex); var result = await Save(plex);
if (result && plex.Enable)
{
BackgroundJob.Enqueue(() => _plexContentCacher.CacheContent());
}
return result; return result;
} }
@ -180,10 +172,6 @@ namespace Ombi.Controllers
} }
} }
var result = await Save(emby); var result = await Save(emby);
if (result && emby.Enable)
{
BackgroundJob.Enqueue(() => _embyContentCacher.Start());
}
return result; return result;
} }