merge live tv tasks

pull/702/head
Luke Pulverenti 10 years ago
parent 7c880201ed
commit f1a715b836

@ -1,58 +0,0 @@
using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Controller.LiveTv;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace MediaBrowser.Server.Implementations.LiveTv
{
class CleanDatabaseScheduledTask : IScheduledTask, IConfigurableScheduledTask
{
private readonly ILiveTvManager _liveTvManager;
public CleanDatabaseScheduledTask(ILiveTvManager liveTvManager)
{
_liveTvManager = liveTvManager;
}
public string Name
{
get { return "Clean TV Database"; }
}
public string Description
{
get { return "Deletes old programs from the tv database."; }
}
public string Category
{
get { return "Live TV"; }
}
public Task Execute(System.Threading.CancellationToken cancellationToken, IProgress<double> progress)
{
var manager = (LiveTvManager)_liveTvManager;
return manager.CleanDatabase(progress, cancellationToken);
}
public IEnumerable<ITaskTrigger> GetDefaultTriggers()
{
return new ITaskTrigger[]
{
new IntervalTrigger{ Interval = TimeSpan.FromHours(12)}
};
}
public bool IsHidden
{
get { return _liveTvManager.ActiveService == null; }
}
public bool IsEnabled
{
get { return true; }
}
}
}

@ -2,6 +2,7 @@
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.Progress;
using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Configuration;
@ -887,7 +888,13 @@ namespace MediaBrowser.Server.Implementations.LiveTv
try
{
await RefreshChannelsInternal(progress, cancellationToken).ConfigureAwait(false);
var innerProgress = new ActionableProgress<double>();
innerProgress.RegisterAction(p => progress.Report(p * .9));
await RefreshChannelsInternal(innerProgress, cancellationToken).ConfigureAwait(false);
innerProgress = new ActionableProgress<double>();
innerProgress.RegisterAction(p => progress.Report(90 + (p * .1)));
await CleanDatabaseInternal(progress, cancellationToken).ConfigureAwait(false);
}
finally
{
@ -998,14 +1005,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv
public async Task CleanDatabase(IProgress<double> progress, CancellationToken cancellationToken)
{
var service = ActiveService;
if (service == null)
{
progress.Report(100);
return;
}
await _refreshSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
try
@ -1018,8 +1017,21 @@ namespace MediaBrowser.Server.Implementations.LiveTv
}
}
private Task CleanDatabaseInternal(IProgress<double> progress, CancellationToken cancellationToken)
{
return DeleteOldPrograms(_programs.Keys.ToList(), progress, cancellationToken);
}
private async Task DeleteOldPrograms(List<Guid> currentIdList, IProgress<double> progress, CancellationToken cancellationToken)
{
var service = ActiveService;
if (service == null)
{
progress.Report(100);
return;
}
var list = _itemRepo.GetItemsOfType(typeof(LiveTvProgram)).ToList();
var numComplete = 0;

@ -153,8 +153,8 @@
<Compile Include="EntryPoints\ServerEventNotifier.cs" />
<Compile Include="EntryPoints\UserDataChangeNotifier.cs" />
<Compile Include="FileOrganization\OrganizerScheduledTask.cs" />
<Compile Include="HttpServer\NetListener\HttpListenerServer.cs" />
<Compile Include="HttpServer\IHttpListener.cs" />
<Compile Include="HttpServer\NetListener\HttpListenerServer.cs" />
<Compile Include="HttpServer\Security\AuthorizationContext.cs" />
<Compile Include="HttpServer\ContainerAdapter.cs" />
<Compile Include="HttpServer\GetSwaggerResource.cs" />
@ -222,7 +222,6 @@
<Compile Include="Library\Validators\StudiosValidator.cs" />
<Compile Include="Library\Validators\YearsPostScanTask.cs" />
<Compile Include="LiveTv\ChannelImageProvider.cs" />
<Compile Include="LiveTv\CleanDatabaseScheduledTask.cs" />
<Compile Include="LiveTv\LiveTvConfigurationFactory.cs" />
<Compile Include="LiveTv\LiveTvDtoService.cs" />
<Compile Include="LiveTv\LiveTvManager.cs" />

Loading…
Cancel
Save