Added the ability to delete requests after they have become available

pull/3703/head
tidusjar 4 years ago
parent 755c16fe01
commit c1529da0e6

@ -231,6 +231,7 @@ namespace Ombi.DependencyInjection
services.AddTransient<IResendFailedRequests, ResendFailedRequests>();
services.AddTransient<IMediaDatabaseRefresh, MediaDatabaseRefresh>();
services.AddTransient<IArrAvailabilityChecker, ArrAvailabilityChecker>();
services.AddTransient<IAutoDeleteRequests, AutoDeleteRequests>();
}
}
}

@ -2,28 +2,29 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Ombi.Core;
using Ombi.Core.Senders;
using Microsoft.Extensions.Logging;
using Ombi.Core.Settings;
using Ombi.Settings.Settings.Models;
using Ombi.Store.Entities;
using Ombi.Store.Repository;
using Ombi.Store.Repository.Requests;
using Quartz;
namespace Ombi.Schedule.Jobs.Ombi
{
public interface IAutoDeleteRequests : IBaseJob { }
public class AutoDeleteRequests : IAutoDeleteRequests
{
private readonly ISettingsService<OmbiSettings> _ombiSettings;
private readonly IMovieRequestRepository _movieRequests;
private readonly ITvRequestRepository _tvRequestRepository;
private readonly ILogger<AutoDeleteRequests> _logger;
public AutoDeleteRequests(ISettingsService<OmbiSettings> ombiSettings, IMovieRequestRepository movieRequest)
public AutoDeleteRequests(ISettingsService<OmbiSettings> ombiSettings, IMovieRequestRepository movieRequest,
ILogger<AutoDeleteRequests> logger, ITvRequestRepository tvRequestRepository)
{
_ombiSettings = ombiSettings;
_movieRequests = movieRequest;
_tvRequestRepository = tvRequestRepository;
_logger = logger;
}
public async Task Execute(IJobExecutionContext job)
@ -33,18 +34,36 @@ namespace Ombi.Schedule.Jobs.Ombi
{
return;
}
await ProcessMovieRequests(settings.AutoDeleteAfterDays);
var date = DateTime.UtcNow.AddDays(-settings.AutoDeleteAfterDays).Date;
await ProcessMovieRequests(date);
await ProcessTvRequests(date);
}
private async Task ProcessMovieRequests(int deleteAfterDays)
private async Task ProcessMovieRequests(DateTime date)
{
var date = DateTime.UtcNow.AddDays(-deleteAfterDays).Date;
var requestsToDelete = await _movieRequests.GetAll().Where(x => x.Available && x.MarkedAsAvailable.HasValue && x.MarkedAsAvailable.Value < date).ToListAsync();
foreach (var request in requestsToDelete)
_logger.LogInformation($"Deleting {requestsToDelete.Count} movie requests that have now been scheduled for deletion, All available requests before {date::MM/dd/yyyy} will be deleted");
foreach (var r in requestsToDelete)
{
_logger.LogInformation($"Deleting movie title {r.Title} as it was approved on {r.MarkedAsApproved:MM/dd/yyyy hh:mm tt}");
}
await _movieRequests.DeleteRange(requestsToDelete);
}
private async Task ProcessTvRequests(DateTime date)
{
var requestsToDelete = await _tvRequestRepository.GetChild().Where(x => x.Available && x.MarkedAsAvailable.HasValue && x.MarkedAsAvailable.Value < date).ToListAsync();
_logger.LogInformation($"Deleting {requestsToDelete.Count} episode requests that have now been scheduled for deletion, All available requests before {date::MM/dd/yyyy} will be deleted");
await _tvRequestRepository.DeleteChildRange(requestsToDelete);
// Check if we have parent requests without any child requests now
var parentRequests = await _tvRequestRepository.Get().Where(x => !x.ChildRequests.Any()).ToListAsync();
await _tvRequestRepository.DeleteRange(parentRequests);
}
private bool _disposed;

@ -0,0 +1,4 @@
namespace Ombi.Schedule.Jobs.Ombi
{
public interface IAutoDeleteRequests : IBaseJob { }
}

@ -67,6 +67,7 @@ namespace Ombi.Schedule
await OmbiQuartz.Instance.AddJob<INewsletterJob>(nameof(INewsletterJob), "System", JobSettingsHelper.Newsletter(s));
await OmbiQuartz.Instance.AddJob<IResendFailedRequests>(nameof(IResendFailedRequests), "System", JobSettingsHelper.ResendFailedRequests(s));
await OmbiQuartz.Instance.AddJob<IMediaDatabaseRefresh>(nameof(IMediaDatabaseRefresh), "System", JobSettingsHelper.MediaDatabaseRefresh(s));
await OmbiQuartz.Instance.AddJob<IAutoDeleteRequests>(nameof(IAutoDeleteRequests), "System", JobSettingsHelper.AutoDeleteRequests(s));
}
private static async Task AddDvrApps(JobSettings s)

@ -16,5 +16,6 @@
public string IssuesPurge { get; set; }
public string RetryRequests { get; set; }
public string MediaDatabaseRefresh { get; set; }
public string AutoDeleteRequests { get; set; }
}
}

@ -76,6 +76,11 @@ namespace Ombi.Settings.Settings.Models
return ValidateCron(Get(s.MediaDatabaseRefresh, Cron.DayInterval(5)));
}
public static string AutoDeleteRequests(JobSettings s)
{
return ValidateCron(Get(s.AutoDeleteRequests, Cron.Daily()));
}
private static string Get(string settings, string defaultCron)
{
return settings.HasValue() ? settings : defaultCron;

@ -12,6 +12,7 @@ namespace Ombi.Store.Repository.Requests
Task<TvRequests> Add(TvRequests request);
Task<ChildRequests> AddChild(ChildRequests request);
Task Delete(TvRequests request);
Task DeleteRange(IEnumerable<TvRequests> request);
Task DeleteChild(ChildRequests request);
IQueryable<TvRequests> Get();
IQueryable<TvRequests> GetLite();

@ -17,6 +17,8 @@ export interface IOmbiSettings extends ISettings {
hideRequestsUsers: boolean;
defaultLanguageCode: string;
disableHealthChecks: boolean;
autoDeleteAvailableRequests: boolean;
autoDeleteAfterDays: number;
}
export interface IUpdateSettings extends ISettings {
@ -146,6 +148,7 @@ export interface IJobSettings {
issuesPurge: string;
retryRequests: string;
mediaDatabaseRefresh: string;
autoDeleteRequests: string;
}
export interface IIssueSettings extends ISettings {

@ -105,6 +105,13 @@
<small *ngIf="form.get('mediaDatabaseRefresh').hasError('required')" class="error-text">The Media Database Refresh is required</small>
<button type="button" class="btn btn-sm btn-primary-outline" (click)="testCron(form.get('mediaDatabaseRefresh')?.value)">Test</button>
</div>
<div class="form-group">
<label for="userImporter" class="control-label">Auto Available Request Deletion</label>
<input type="text" class="form-control form-control-custom" [ngClass]="{'form-error': form.get('autoDeleteRequests').hasError('required')}" id="autoDeleteRequests" name="autoDeleteRequests" formControlName="autoDeleteRequests">
<small *ngIf="form.get('autoDeleteRequests').hasError('required')" class="error-text">Auto Available Request Deletion is required</small>
<button type="button" class="btn btn-sm btn-primary-outline" (click)="testCron(form.get('autoDeleteRequests')?.value)">Test</button>
</div>
</div>
<div class="form-group">
<div>

@ -34,7 +34,8 @@ export class JobsComponent implements OnInit {
lidarrArtistSync: [x.lidarrArtistSync, Validators.required],
issuesPurge: [x.issuesPurge, Validators.required],
retryRequests: [x.retryRequests, Validators.required],
mediaDatabaseRefresh: [x.mediaDatabaseRefresh, Validators.required]
mediaDatabaseRefresh: [x.mediaDatabaseRefresh, Validators.required],
autoDeleteRequests: [x.autoDeleteRequests, Validators.required]
});
});
}

@ -35,6 +35,17 @@
Hide requests from other users
</mat-checkbox>
</div>
<div>
<mat-checkbox formControlName="autoDeleteAvailableRequests">
Auto Delete Available Requests
</mat-checkbox>
</div>
<div *ngIf="form.get('autoDeleteAvailableRequests').value">
<mat-form-field appearance="outline" >
<mat-label>Delete After Days of Availbility</mat-label>
<input matInput formControlName="autoDeleteAfterDays">
</mat-form-field>
</div>
<div>
<mat-checkbox formControlName="ignoreCertificateErrors" matTooltip="Enable if you are having connectivity problems over SSL">
Ignore any certificate errors (Please restart after changing)

@ -30,10 +30,11 @@ export class OmbiComponent implements OnInit {
doNotSendNotificationsForAutoApprove: [x.doNotSendNotificationsForAutoApprove],
hideRequestsUsers: [x.hideRequestsUsers],
defaultLanguageCode: [x.defaultLanguageCode],
disableHealthChecks: [x.disableHealthChecks]
disableHealthChecks: [x.disableHealthChecks],
autoDeleteAvailableRequests: [x.autoDeleteAvailableRequests],
autoDeleteAfterDays: [x.autoDeleteAfterDays]
});
});
debugger;
this.langauges = <ILanguageRefine[]>languageData
}

@ -146,6 +146,14 @@ namespace Ombi.Controllers.V1
return true;
}
[HttpPost("autodeleterequests")]
public async Task<bool> StartAutoDeleteRequests()
{
await OmbiQuartz.TriggerJob(nameof(IAutoDeleteRequests), "System");
return true;
}
/// <summary>
/// Runs the newsletter
/// </summary>

@ -575,6 +575,7 @@ namespace Ombi.Controllers.V1
j.IssuesPurge = j.IssuesPurge.HasValue() ? j.IssuesPurge : JobSettingsHelper.IssuePurge(j);
j.RetryRequests = j.RetryRequests.HasValue() ? j.RetryRequests : JobSettingsHelper.ResendFailedRequests(j);
j.MediaDatabaseRefresh = j.MediaDatabaseRefresh.HasValue() ? j.MediaDatabaseRefresh : JobSettingsHelper.MediaDatabaseRefresh(j);
j.AutoDeleteRequests = j.AutoDeleteRequests.HasValue() ? j.AutoDeleteRequests : JobSettingsHelper.AutoDeleteRequests(j);
return j;
}

Loading…
Cancel
Save