parent
40f384968a
commit
ec58b8b595
@ -1,33 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
|
||||
namespace NzbDrone.Core.Jobs
|
||||
{
|
||||
public interface IJob
|
||||
{
|
||||
/// <summary>
|
||||
/// Name of the timer.
|
||||
/// This is the name that will be visible in all UI elements
|
||||
/// </summary>\\\
|
||||
string Name { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Default Interval that this job should run at. In seconds.
|
||||
/// </summary>
|
||||
/// <remarks>Setting this value to 0 means the job will not be
|
||||
/// executed by the schedule and is only triggered manually.</remarks>
|
||||
TimeSpan DefaultInterval { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Starts the job
|
||||
/// </summary>
|
||||
/// <param name="notification">Notification object that is passed in by JobProvider.
|
||||
/// this object should be used to update the progress on the UI</param>
|
||||
/// <param name="targetId">The that should be used to limit the target of this job</param>
|
||||
/// /// <param name="secondaryTargetId">The that should be used to limit the target of this job</param>
|
||||
void Start(ProgressNotification notification, dynamic options);
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Providers;
|
||||
|
||||
namespace NzbDrone.Core.Jobs.Implementations
|
||||
{
|
||||
public class CleanupRecycleBinJob : IJob
|
||||
{
|
||||
private readonly RecycleBinProvider _recycleBinProvider;
|
||||
|
||||
public CleanupRecycleBinJob(RecycleBinProvider recycleBinProvider)
|
||||
{
|
||||
_recycleBinProvider = recycleBinProvider;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "Cleanup Recycle Bin"; }
|
||||
}
|
||||
|
||||
public TimeSpan DefaultInterval
|
||||
{
|
||||
get { return TimeSpan.FromDays(24); }
|
||||
}
|
||||
|
||||
public void Start(ProgressNotification notification, dynamic options)
|
||||
{
|
||||
_recycleBinProvider.Cleanup();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Providers.Converting;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Jobs.Implementations
|
||||
{
|
||||
public class ConvertEpisodeJob : IJob
|
||||
{
|
||||
private readonly HandbrakeProvider _handbrakeProvider;
|
||||
private readonly AtomicParsleyProvider _atomicParsleyProvider;
|
||||
private readonly IEpisodeService _episodeService;
|
||||
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public ConvertEpisodeJob(HandbrakeProvider handbrakeProvider, AtomicParsleyProvider atomicParsleyProvider,
|
||||
IEpisodeService episodeService)
|
||||
{
|
||||
_handbrakeProvider = handbrakeProvider;
|
||||
_atomicParsleyProvider = atomicParsleyProvider;
|
||||
_episodeService = episodeService;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "Convert Episode"; }
|
||||
}
|
||||
|
||||
public TimeSpan DefaultInterval
|
||||
{
|
||||
get { return TimeSpan.FromTicks(0); }
|
||||
}
|
||||
|
||||
public void Start(ProgressNotification notification, dynamic options)
|
||||
{
|
||||
|
||||
if (options == null || options.EpisodeId <= 0)
|
||||
throw new ArgumentNullException(options);
|
||||
|
||||
Episode episode = _episodeService.GetEpisode((int)options.EpisodeId);
|
||||
notification.CurrentMessage = String.Format("Starting Conversion for {0}", episode);
|
||||
var outputFile = _handbrakeProvider.ConvertFile(episode, notification);
|
||||
|
||||
if (String.IsNullOrEmpty(outputFile))
|
||||
notification.CurrentMessage = String.Format("Conversion failed for {0}", episode);
|
||||
|
||||
_atomicParsleyProvider.RunAtomicParsley(episode, outputFile);
|
||||
|
||||
notification.CurrentMessage = String.Format("Conversion completed for {0}", episode);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Helpers;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Jobs.Implementations
|
||||
{
|
||||
public class DiskScanJob : IJob
|
||||
{
|
||||
private readonly IDiskScanService _diskScanService;
|
||||
private readonly IConfigService _configService;
|
||||
private readonly ISeriesRepository _seriesRepository;
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public DiskScanJob(IDiskScanService diskScanService,
|
||||
IConfigService configService, ISeriesRepository seriesRepository)
|
||||
{
|
||||
_diskScanService = diskScanService;
|
||||
_configService = configService;
|
||||
_seriesRepository = seriesRepository;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "Media File Scan"; }
|
||||
}
|
||||
|
||||
public TimeSpan DefaultInterval
|
||||
{
|
||||
get { return TimeSpan.FromHours(6); }
|
||||
}
|
||||
|
||||
public virtual void Start(ProgressNotification notification, dynamic options)
|
||||
{
|
||||
IList<Series> seriesToScan;
|
||||
if (options == null || options.SeriesId == 0)
|
||||
{
|
||||
if (_configService.IgnoreArticlesWhenSortingSeries)
|
||||
seriesToScan = _seriesRepository.All().OrderBy(o => o.Title.IgnoreArticles()).ToList();
|
||||
|
||||
else
|
||||
seriesToScan = _seriesRepository.All().OrderBy(o => o.Title).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
seriesToScan = new List<Series>() { _seriesRepository.Get((int)options.SeriesId) };
|
||||
}
|
||||
|
||||
foreach (var series in seriesToScan)
|
||||
{
|
||||
try
|
||||
{
|
||||
notification.CurrentMessage = string.Format("Scanning disk for '{0}'", series.Title);
|
||||
_diskScanService.Scan(series);
|
||||
notification.CurrentMessage = string.Format("Disk Scan completed for '{0}'", series.Title);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorException("An error has occurred while scanning " + series.Title, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Providers;
|
||||
|
||||
namespace NzbDrone.Core.Jobs.Implementations
|
||||
{
|
||||
public class EmptyRecycleBinJob : IJob
|
||||
{
|
||||
private readonly RecycleBinProvider _recycleBinProvider;
|
||||
|
||||
public EmptyRecycleBinJob(RecycleBinProvider recycleBinProvider)
|
||||
{
|
||||
_recycleBinProvider = recycleBinProvider;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "Empty Recycle Bin"; }
|
||||
}
|
||||
|
||||
public TimeSpan DefaultInterval
|
||||
{
|
||||
get { return TimeSpan.FromTicks(0); }
|
||||
}
|
||||
|
||||
public void Start(ProgressNotification notification, dynamic options)
|
||||
{
|
||||
_recycleBinProvider.Empty();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Providers;
|
||||
|
||||
namespace NzbDrone.Core.Jobs.Implementations
|
||||
{
|
||||
public class PostDownloadScanJob : IJob
|
||||
{
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private readonly IDropFolderImportService _dropFolderImportService;
|
||||
private readonly IConfigService _configService;
|
||||
private readonly DiskProvider _diskProvider;
|
||||
|
||||
public PostDownloadScanJob(IDropFolderImportService dropFolderImportService,IConfigService configService, DiskProvider diskProvider)
|
||||
{
|
||||
_dropFolderImportService = dropFolderImportService;
|
||||
_configService = configService;
|
||||
_diskProvider = diskProvider;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "Drop folder monitor"; }
|
||||
}
|
||||
|
||||
public TimeSpan DefaultInterval
|
||||
{
|
||||
get { return TimeSpan.FromMinutes(1); }
|
||||
}
|
||||
|
||||
public virtual void Start(ProgressNotification notification, dynamic options)
|
||||
{
|
||||
string dropFolder;
|
||||
|
||||
if (options != null && !String.IsNullOrWhiteSpace(options.Path))
|
||||
dropFolder = options.Path;
|
||||
|
||||
else
|
||||
dropFolder = _configService.DownloadClientTvDirectory;
|
||||
|
||||
if (String.IsNullOrWhiteSpace(dropFolder))
|
||||
{
|
||||
Logger.Debug("No drop folder is defined. Skipping.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_diskProvider.FolderExists(dropFolder))
|
||||
{
|
||||
Logger.Warn("Unable to Scan for New Downloads - folder Doesn't exist: [{0}]", dropFolder);
|
||||
return;
|
||||
}
|
||||
|
||||
_dropFolderImportService.ProcessDropFolder(dropFolder);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Jobs.Implementations
|
||||
{
|
||||
public class RefreshEpisodeMetadata : IJob
|
||||
{
|
||||
private readonly IMediaFileService _mediaFileService;
|
||||
private readonly ISeriesRepository _seriesRepository;
|
||||
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public RefreshEpisodeMetadata(IMediaFileService mediaFileService, ISeriesRepository seriesRepository)
|
||||
{
|
||||
_mediaFileService = mediaFileService;
|
||||
_seriesRepository = seriesRepository;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "Refresh Episode Metadata"; }
|
||||
}
|
||||
|
||||
public TimeSpan DefaultInterval
|
||||
{
|
||||
get { return TimeSpan.FromTicks(0); }
|
||||
}
|
||||
|
||||
public void Start(ProgressNotification notification, dynamic options)
|
||||
{
|
||||
List<Series> seriesToRefresh;
|
||||
|
||||
if (options == null || options.SeriesId <= 0)
|
||||
seriesToRefresh = _seriesRepository.All().ToList();
|
||||
|
||||
else
|
||||
seriesToRefresh = new List<Series> { _seriesRepository.Get(options.SeriesId) };
|
||||
|
||||
foreach (var series in seriesToRefresh)
|
||||
{
|
||||
RefreshMetadata(notification, series);
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshMetadata(ProgressNotification notification, Series series)
|
||||
{
|
||||
notification.CurrentMessage = String.Format("Refreshing episode metadata for '{0}'", series.Title);
|
||||
|
||||
Logger.Debug("Getting episodes from database for series: {0}", series.Id);
|
||||
var episodeFiles = _mediaFileService.GetFilesBySeries(series.Id);
|
||||
|
||||
if (episodeFiles == null || episodeFiles.Count == 0)
|
||||
{
|
||||
Logger.Warn("No episodes in database found for series: {0}", series.Id);
|
||||
return;
|
||||
}
|
||||
|
||||
notification.CurrentMessage = String.Format("Episode metadata refresh completed for {0}", series.Title);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Jobs.Implementations
|
||||
{
|
||||
public class RenameSeasonJob : IJob
|
||||
{
|
||||
private readonly IMediaFileService _mediaFileService;
|
||||
private readonly ISeriesRepository _seriesRepository;
|
||||
private readonly IMessageAggregator _messageAggregator;
|
||||
private readonly IMoveEpisodeFiles _episodeFilesMover;
|
||||
|
||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public RenameSeasonJob(IMediaFileService mediaFileService, ISeriesRepository seriesRepository, IMessageAggregator messageAggregator, IMoveEpisodeFiles episodeFilesMover)
|
||||
{
|
||||
_mediaFileService = mediaFileService;
|
||||
_seriesRepository = seriesRepository;
|
||||
_messageAggregator = messageAggregator;
|
||||
_episodeFilesMover = episodeFilesMover;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "Rename Season"; }
|
||||
}
|
||||
|
||||
public TimeSpan DefaultInterval
|
||||
{
|
||||
get { return TimeSpan.FromTicks(0); }
|
||||
}
|
||||
|
||||
public void Start(ProgressNotification notification, dynamic options)
|
||||
{
|
||||
if (options == null || options.SeriesId <= 0)
|
||||
throw new ArgumentException("options");
|
||||
|
||||
if (options.SeasonNumber < 0)
|
||||
throw new ArgumentException("options.SeasonNumber");
|
||||
|
||||
var series = _seriesRepository.Get((int)options.SeriesId);
|
||||
|
||||
notification.CurrentMessage = String.Format("Renaming episodes for {0} Season {1}", series.Title, options.SeasonNumber);
|
||||
|
||||
logger.Debug("Getting episodes from database for series: {0} and season: {1}", options.SeriesId, options.SeasonNumber);
|
||||
IList<EpisodeFile> episodeFiles = _mediaFileService.GetFilesBySeason((int)options.SeriesId, (int)options.SeasonNumber);
|
||||
|
||||
if (episodeFiles == null || !episodeFiles.Any())
|
||||
{
|
||||
logger.Warn("No episodes in database found for series: {0} and season: {1}.", options.SeriesId, options.SeasonNumber);
|
||||
return;
|
||||
}
|
||||
|
||||
var newEpisodeFiles = new List<EpisodeFile>();
|
||||
var oldEpisodeFiles = new List<EpisodeFile>();
|
||||
|
||||
foreach (var episodeFile in episodeFiles)
|
||||
{
|
||||
try
|
||||
{
|
||||
var oldFile = new EpisodeFile(episodeFile);
|
||||
var newFile = _episodeFilesMover.MoveEpisodeFile(episodeFile);
|
||||
|
||||
if (newFile != null)
|
||||
{
|
||||
newEpisodeFiles.Add(newFile);
|
||||
oldEpisodeFiles.Add(oldFile);
|
||||
}
|
||||
}
|
||||
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.WarnException("An error has occurred while renaming file", e);
|
||||
}
|
||||
}
|
||||
|
||||
if (!oldEpisodeFiles.Any())
|
||||
{
|
||||
logger.Trace("No episodes were renamed for: {0} Season {1}, no changes were made", series.Title,
|
||||
options.SeasonNumber);
|
||||
notification.CurrentMessage = String.Format("Rename completed for: {0} Season {1}, no changes were made", series.Title, options.SeasonNumber);
|
||||
return;
|
||||
}
|
||||
|
||||
//Start AfterRename
|
||||
_messageAggregator.PublishEvent(new SeriesRenamedEvent(series));
|
||||
|
||||
notification.CurrentMessage = String.Format("Rename completed for {0} Season {1}", series.Title, options.SeasonNumber);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Jobs.Implementations
|
||||
{
|
||||
public class RenameSeriesJob : IJob
|
||||
{
|
||||
private readonly IMediaFileService _mediaFileService;
|
||||
private readonly ISeriesRepository _seriesRepository;
|
||||
private readonly IMessageAggregator _messageAggregator;
|
||||
private readonly IMoveEpisodeFiles _moveEpisodeFiles;
|
||||
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public RenameSeriesJob(IMediaFileService mediaFileService, ISeriesRepository seriesRepository, IMessageAggregator messageAggregator, IMoveEpisodeFiles moveEpisodeFiles)
|
||||
{
|
||||
_mediaFileService = mediaFileService;
|
||||
_seriesRepository = seriesRepository;
|
||||
_messageAggregator = messageAggregator;
|
||||
_moveEpisodeFiles = moveEpisodeFiles;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "Rename Series"; }
|
||||
}
|
||||
|
||||
public TimeSpan DefaultInterval
|
||||
{
|
||||
get { return TimeSpan.FromTicks(0); }
|
||||
}
|
||||
|
||||
public void Start(ProgressNotification notification, dynamic options)
|
||||
{
|
||||
List<Series> seriesToRename;
|
||||
|
||||
if (options == null || options.SeriesId <= 0)
|
||||
{
|
||||
seriesToRename = _seriesRepository.All().ToList();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
seriesToRename = new List<Series> { _seriesRepository.Get((int)options.SeriesId) };
|
||||
}
|
||||
|
||||
foreach (var series in seriesToRename)
|
||||
{
|
||||
notification.CurrentMessage = String.Format("Renaming episodes for '{0}'", series.Title);
|
||||
|
||||
Logger.Debug("Getting episodes from database for series: {0}", series.Id);
|
||||
var episodeFiles = _mediaFileService.GetFilesBySeries(series.Id);
|
||||
|
||||
if (episodeFiles == null || episodeFiles.Count == 0)
|
||||
{
|
||||
Logger.Warn("No episodes in database found for series: {0}", series.Id);
|
||||
return;
|
||||
}
|
||||
|
||||
var newEpisodeFiles = new List<EpisodeFile>();
|
||||
var oldEpisodeFiles = new List<EpisodeFile>();
|
||||
|
||||
foreach (var episodeFile in episodeFiles)
|
||||
{
|
||||
try
|
||||
{
|
||||
var oldFile = new EpisodeFile(episodeFile);
|
||||
var newFile = _moveEpisodeFiles.MoveEpisodeFile(episodeFile);
|
||||
|
||||
if (newFile != null)
|
||||
{
|
||||
newEpisodeFiles.Add(newFile);
|
||||
oldEpisodeFiles.Add(oldFile);
|
||||
}
|
||||
}
|
||||
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.WarnException("An error has occurred while renaming file", e);
|
||||
}
|
||||
}
|
||||
|
||||
//Start AfterRename
|
||||
|
||||
_messageAggregator.PublishEvent(new SeriesRenamedEvent(series));
|
||||
|
||||
notification.CurrentMessage = String.Format("Rename completed for {0}", series.Title);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
using System;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
|
||||
namespace NzbDrone.Core.Jobs.Implementations
|
||||
{
|
||||
public class RssSyncJob : IJob
|
||||
{
|
||||
private readonly IRssSyncService _rssSyncServiceService;
|
||||
private readonly IConfigService _configService;
|
||||
|
||||
|
||||
public RssSyncJob(IRssSyncService rssSyncServiceService, IConfigService configService)
|
||||
{
|
||||
_rssSyncServiceService = rssSyncServiceService;
|
||||
_configService = configService;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "RSS Sync"; }
|
||||
}
|
||||
|
||||
public TimeSpan DefaultInterval
|
||||
{
|
||||
get { return TimeSpan.FromMinutes(_configService.RssSyncInterval); }
|
||||
}
|
||||
|
||||
public void Start(ProgressNotification notification, dynamic options)
|
||||
{
|
||||
_rssSyncServiceService.Sync();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.DataAugmentation.DailySeries;
|
||||
using NzbDrone.Core.Helpers;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Jobs.Implementations
|
||||
{
|
||||
public class UpdateInfoJob : IJob
|
||||
{
|
||||
private readonly ISeriesService _seriesService;
|
||||
private readonly IEpisodeService _episodeService;
|
||||
private readonly DailySeriesService _dailySeriesService;
|
||||
private readonly IConfigService _configService;
|
||||
private readonly ISeriesRepository _seriesRepository;
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public UpdateInfoJob(ISeriesService seriesService, IEpisodeService episodeService,
|
||||
DailySeriesService dailySeriesService, IConfigService configService, ISeriesRepository seriesRepository)
|
||||
{
|
||||
_seriesService = seriesService;
|
||||
_episodeService = episodeService;
|
||||
_dailySeriesService = dailySeriesService;
|
||||
_configService = configService;
|
||||
_seriesRepository = seriesRepository;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "Update Episode Info"; }
|
||||
}
|
||||
|
||||
public TimeSpan DefaultInterval
|
||||
{
|
||||
get { return TimeSpan.FromHours(12); }
|
||||
}
|
||||
|
||||
public virtual void Start(ProgressNotification notification, dynamic options)
|
||||
{
|
||||
IList<Series> listOfSeriesToUpdate;
|
||||
if (options == null || options.SeriesId == 0)
|
||||
{
|
||||
if (_configService.IgnoreArticlesWhenSortingSeries)
|
||||
{
|
||||
listOfSeriesToUpdate = _seriesRepository.All().OrderBy(o => o.Title.IgnoreArticles()).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
listOfSeriesToUpdate = _seriesRepository.All().OrderBy(o => o.Title).ToList();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
listOfSeriesToUpdate = new List<Series>
|
||||
{
|
||||
_seriesRepository.Get((int) options.SeriesId)
|
||||
};
|
||||
}
|
||||
|
||||
//Update any Daily Series in the DB with the IsDaily flag
|
||||
_dailySeriesService.UpdateDailySeries();
|
||||
|
||||
foreach (var seriesToUpdate in listOfSeriesToUpdate)
|
||||
{
|
||||
var series = seriesToUpdate;
|
||||
|
||||
try
|
||||
{
|
||||
notification.CurrentMessage = "Updating " + series.Title;
|
||||
series = _seriesService.UpdateSeriesInfo(series.Id);
|
||||
_episodeService.RefreshEpisodeInfo(series);
|
||||
notification.CurrentMessage = "Update completed for " + series.Title;
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.ErrorException("Failed to update episode info for series: " + series.Title, ex);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Providers;
|
||||
|
||||
namespace NzbDrone.Core.Jobs.Implementations
|
||||
{
|
||||
public class XemUpdateJob : IJob
|
||||
{
|
||||
private readonly XemProvider _xemProvider;
|
||||
|
||||
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public XemUpdateJob(XemProvider xemProvider)
|
||||
{
|
||||
_xemProvider = xemProvider;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "XEM Update"; }
|
||||
}
|
||||
|
||||
public TimeSpan DefaultInterval
|
||||
{
|
||||
get { return TimeSpan.FromHours(12); }
|
||||
}
|
||||
|
||||
public virtual void Start(ProgressNotification notification, dynamic options)
|
||||
{
|
||||
if (options == null || options.SeriesId == 0)
|
||||
{
|
||||
_logger.Trace("Starting XEM Update for all series");
|
||||
_xemProvider.UpdateMappings();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
_logger.Trace("Starting XEM Update for series: {0}", options.SeriesId);
|
||||
_xemProvider.UpdateMappings((int)options.SeriesId);
|
||||
}
|
||||
|
||||
_logger.Trace("XEM Update complete");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,188 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Providers;
|
||||
|
||||
namespace NzbDrone.Core.Jobs
|
||||
{
|
||||
public interface IJobController
|
||||
{
|
||||
bool IsProcessing { get; }
|
||||
IEnumerable<JobQueueItem> Queue { get; }
|
||||
void EnqueueScheduled();
|
||||
void Enqueue(Type jobType, dynamic options = null, JobQueueItem.JobSourceType source = JobQueueItem.JobSourceType.User);
|
||||
bool Enqueue(string jobTypeString);
|
||||
}
|
||||
|
||||
public class JobController : IJobController, IHandle<ApplicationShutdownRequested>
|
||||
{
|
||||
private readonly NotificationProvider _notificationProvider;
|
||||
private readonly IEnumerable<IJob> _jobs;
|
||||
private readonly IJobRepository _jobRepository;
|
||||
private readonly Logger _logger;
|
||||
|
||||
private readonly BlockingCollection<JobQueueItem> _queue = new BlockingCollection<JobQueueItem>();
|
||||
|
||||
private ProgressNotification _notification;
|
||||
private readonly CancellationTokenSource _cancellationTokenSource;
|
||||
|
||||
public JobController(NotificationProvider notificationProvider, IEnumerable<IJob> jobs, IJobRepository jobRepository, Logger logger)
|
||||
{
|
||||
_notificationProvider = notificationProvider;
|
||||
_jobs = jobs;
|
||||
_jobRepository = jobRepository;
|
||||
_logger = logger;
|
||||
_cancellationTokenSource = new CancellationTokenSource();
|
||||
Task.Factory.StartNew(ProcessQueue, _cancellationTokenSource.Token);
|
||||
}
|
||||
|
||||
public bool IsProcessing { get; private set; }
|
||||
|
||||
public IEnumerable<JobQueueItem> Queue
|
||||
{
|
||||
get
|
||||
{
|
||||
return _queue;
|
||||
}
|
||||
}
|
||||
|
||||
public void EnqueueScheduled()
|
||||
{
|
||||
if (IsProcessing)
|
||||
{
|
||||
_logger.Trace("Queue is already running. Ignoring scheduler request.");
|
||||
return;
|
||||
}
|
||||
|
||||
var pendingJobs = _jobRepository.GetPendingJobs()
|
||||
.Select(c => _jobs.Single(t => t.GetType().ToString() == c.Type)
|
||||
.GetType()).ToList();
|
||||
|
||||
|
||||
pendingJobs.ForEach(jobType => Enqueue(jobType, source: JobQueueItem.JobSourceType.Scheduler));
|
||||
_logger.Trace("{0} Scheduled tasks have been added to the queue", pendingJobs.Count);
|
||||
}
|
||||
|
||||
public void Enqueue(Type jobType, dynamic options = null, JobQueueItem.JobSourceType source = JobQueueItem.JobSourceType.User)
|
||||
{
|
||||
IsProcessing = true;
|
||||
|
||||
var queueItem = new JobQueueItem
|
||||
{
|
||||
JobType = jobType,
|
||||
Options = options,
|
||||
Source = source
|
||||
};
|
||||
|
||||
_logger.Debug("Attempting to queue {0}", queueItem);
|
||||
|
||||
lock (_queue)
|
||||
{
|
||||
if (!_queue.Contains(queueItem))
|
||||
{
|
||||
_queue.Add(queueItem);
|
||||
_logger.Trace("Job {0} added to the queue. current items in queue: {1}", queueItem, _queue.Count);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Info("{0} already exists in the queue. Skipping. current items in queue: {1}", queueItem, _queue.Count);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public bool Enqueue(string jobTypeString)
|
||||
{
|
||||
var type = Type.GetType(jobTypeString);
|
||||
|
||||
if (type == null)
|
||||
return false;
|
||||
|
||||
Enqueue(type);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void ProcessQueue()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
IsProcessing = false;
|
||||
var item = _queue.Take();
|
||||
Execute(item);
|
||||
}
|
||||
catch (ThreadAbortException e)
|
||||
{
|
||||
_logger.Warn(e.Message);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.ErrorException("Error has occurred in queue processor thread", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Execute(JobQueueItem queueItem)
|
||||
{
|
||||
IsProcessing = true;
|
||||
|
||||
var jobImplementation = _jobs.SingleOrDefault(t => t.GetType() == queueItem.JobType);
|
||||
if (jobImplementation == null)
|
||||
{
|
||||
_logger.Error("Unable to locate implementation for '{0}'. Make sure it is properly registered.", queueItem.JobType);
|
||||
return;
|
||||
}
|
||||
|
||||
var jobDefinition = _jobRepository.GetDefinition(queueItem.JobType);
|
||||
using (_notification = new ProgressNotification(jobImplementation.Name))
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.Debug("Starting {0}. Last execution {1}", queueItem, jobDefinition.LastExecution);
|
||||
|
||||
var sw = Stopwatch.StartNew();
|
||||
|
||||
_notificationProvider.Register(_notification);
|
||||
jobImplementation.Start(_notification, queueItem.Options);
|
||||
_notification.Status = ProgressNotificationStatus.Completed;
|
||||
|
||||
jobDefinition.LastExecution = DateTime.Now;
|
||||
jobDefinition.Success = true;
|
||||
|
||||
sw.Stop();
|
||||
_logger.Debug("Job {0} successfully completed in {1:0}.{2} seconds.", queueItem, sw.Elapsed.TotalSeconds, sw.Elapsed.Milliseconds / 100,
|
||||
sw.Elapsed.Seconds);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.ErrorException("An error has occurred while executing job [" + jobImplementation.Name + "].", e);
|
||||
_notification.Status = ProgressNotificationStatus.Failed;
|
||||
_notification.CurrentMessage = jobImplementation.Name + " Failed.";
|
||||
|
||||
jobDefinition.LastExecution = DateTime.Now;
|
||||
jobDefinition.Success = false;
|
||||
}
|
||||
}
|
||||
|
||||
//Only update last execution status if was triggered by the scheduler
|
||||
if (queueItem.Options == null)
|
||||
{
|
||||
_jobRepository.Update(jobDefinition);
|
||||
}
|
||||
}
|
||||
|
||||
public void Handle(ApplicationShutdownRequested message)
|
||||
{
|
||||
_cancellationTokenSource.Cancel();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
using NzbDrone.Common.Messaging;
|
||||
|
||||
namespace NzbDrone.Core.MediaFiles.Commands
|
||||
{
|
||||
public class CleanUpRecycleBinCommand : ICommand
|
||||
{
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="JavaScriptLibraryMappings">
|
||||
<file url="PROJECT" libraries="{jQuery-1.9.1, libraries}" />
|
||||
<file url="PROJECT" libraries="{libraries}" />
|
||||
</component>
|
||||
</project>
|
||||
|
||||
|
Loading…
Reference in new issue