add ability to configure scheduled task time limit
This commit is contained in:
parent
6e1178a07b
commit
0a7dc313fd
|
@ -3,7 +3,6 @@ using MediaBrowser.Common.ScheduledTasks;
|
|||
using MediaBrowser.Controller.Net;
|
||||
using MediaBrowser.Model.Tasks;
|
||||
using ServiceStack;
|
||||
using ServiceStack.Text.Controller;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
|
|
@ -99,6 +99,11 @@ namespace MediaBrowser.Common.ScheduledTasks
|
|||
info.SystemEvent = systemEventTrigger.SystemEvent;
|
||||
}
|
||||
|
||||
if (trigger.TaskOptions != null)
|
||||
{
|
||||
info.MaxRuntimeMs = trigger.TaskOptions.MaxRuntimeMs;
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
|
@ -111,6 +116,11 @@ namespace MediaBrowser.Common.ScheduledTasks
|
|||
/// <exception cref="System.ArgumentException">Invalid trigger type: + info.Type</exception>
|
||||
public static ITaskTrigger GetTrigger(TaskTriggerInfo info)
|
||||
{
|
||||
var options = new TaskExecutionOptions
|
||||
{
|
||||
MaxRuntimeMs = info.MaxRuntimeMs
|
||||
};
|
||||
|
||||
if (info.Type.Equals(typeof(DailyTrigger).Name, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (!info.TimeOfDayTicks.HasValue)
|
||||
|
@ -120,7 +130,8 @@ namespace MediaBrowser.Common.ScheduledTasks
|
|||
|
||||
return new DailyTrigger
|
||||
{
|
||||
TimeOfDay = TimeSpan.FromTicks(info.TimeOfDayTicks.Value)
|
||||
TimeOfDay = TimeSpan.FromTicks(info.TimeOfDayTicks.Value),
|
||||
TaskOptions = options
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -139,7 +150,8 @@ namespace MediaBrowser.Common.ScheduledTasks
|
|||
return new WeeklyTrigger
|
||||
{
|
||||
TimeOfDay = TimeSpan.FromTicks(info.TimeOfDayTicks.Value),
|
||||
DayOfWeek = info.DayOfWeek.Value
|
||||
DayOfWeek = info.DayOfWeek.Value,
|
||||
TaskOptions = options
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -152,7 +164,8 @@ namespace MediaBrowser.Common.ScheduledTasks
|
|||
|
||||
return new IntervalTrigger
|
||||
{
|
||||
Interval = TimeSpan.FromTicks(info.IntervalTicks.Value)
|
||||
Interval = TimeSpan.FromTicks(info.IntervalTicks.Value),
|
||||
TaskOptions = options
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -165,7 +178,8 @@ namespace MediaBrowser.Common.ScheduledTasks
|
|||
|
||||
return new SystemEventTrigger
|
||||
{
|
||||
SystemEvent = info.SystemEvent.Value
|
||||
SystemEvent = info.SystemEvent.Value,
|
||||
TaskOptions = options
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace MediaBrowser.Common.ScheduledTasks
|
||||
{
|
||||
/// <summary>
|
||||
|
|
|
@ -36,5 +36,11 @@ namespace MediaBrowser.Model.Tasks
|
|||
/// </summary>
|
||||
/// <value>The day of week.</value>
|
||||
public DayOfWeek? DayOfWeek { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the maximum runtime ms.
|
||||
/// </summary>
|
||||
/// <value>The maximum runtime ms.</value>
|
||||
public int? MaxRuntimeMs { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,8 @@
|
|||
"MessageKeyUpdated": "Thank you. Your supporter key has been updated.",
|
||||
"MessageKeyRemoved": "Thank you. Your supporter key has been removed.",
|
||||
"ErrorLaunchingChromecast": "There was an error launching chromecast. Please ensure your device is connected to your wireless network.",
|
||||
"ValueTimeLimitSingleHour": "Time limit: 1 hour",
|
||||
"ValueTimeLimitMultiHour": "Time limit: {0} hours",
|
||||
"HeaderSearch": "Search",
|
||||
"ValueDateCreated": "Date created: {0}",
|
||||
"LabelArtist": "Artist",
|
||||
|
|
|
@ -100,6 +100,7 @@
|
|||
"ReferToMediaLibraryWiki": "Refer to the media library wiki.",
|
||||
"LabelCountry": "Country:",
|
||||
"LabelLanguage": "Language:",
|
||||
"LabelTimeLimitHours": "Time limit (hours):",
|
||||
"ButtonJoinTheDevelopmentTeam": "Join the Development Team",
|
||||
"HeaderPreferredMetadataLanguage": "Preferred metadata language:",
|
||||
"LabelSaveLocalMetadata": "Save artwork and metadata into media folders",
|
||||
|
|
|
@ -4,9 +4,7 @@ using MediaBrowser.Controller.Entities;
|
|||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.MediaEncoding;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MoreLinq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
@ -30,10 +28,6 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
|
|||
/// </summary>
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
|
||||
private readonly List<Video> _newlyAddedItems = new List<Video>();
|
||||
|
||||
private const int NewItemDelay = 30000;
|
||||
|
||||
/// <summary>
|
||||
/// The current new item timer
|
||||
/// </summary>
|
||||
|
@ -59,70 +53,6 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
|
|||
_itemRepo = itemRepo;
|
||||
_appPaths = appPaths;
|
||||
_encodingManager = encodingManager;
|
||||
|
||||
libraryManager.ItemAdded += libraryManager_ItemAdded;
|
||||
libraryManager.ItemUpdated += libraryManager_ItemAdded;
|
||||
}
|
||||
|
||||
void libraryManager_ItemAdded(object sender, ItemChangeEventArgs e)
|
||||
{
|
||||
var video = e.Item as Video;
|
||||
|
||||
if (video != null)
|
||||
{
|
||||
lock (_newlyAddedItems)
|
||||
{
|
||||
_newlyAddedItems.Add(video);
|
||||
|
||||
if (NewItemTimer == null)
|
||||
{
|
||||
NewItemTimer = new Timer(NewItemTimerCallback, null, NewItemDelay, Timeout.Infinite);
|
||||
}
|
||||
else
|
||||
{
|
||||
NewItemTimer.Change(NewItemDelay, Timeout.Infinite);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async void NewItemTimerCallback(object state)
|
||||
{
|
||||
List<Video> newItems;
|
||||
|
||||
// Lock the list and release all resources
|
||||
lock (_newlyAddedItems)
|
||||
{
|
||||
newItems = _newlyAddedItems.DistinctBy(i => i.Id).ToList();
|
||||
_newlyAddedItems.Clear();
|
||||
|
||||
NewItemTimer.Dispose();
|
||||
NewItemTimer = null;
|
||||
}
|
||||
|
||||
// Limit to video files to reduce changes of ffmpeg crash dialog
|
||||
foreach (var item in newItems
|
||||
.Where(i => i.LocationType == LocationType.FileSystem && i.VideoType == VideoType.VideoFile && string.IsNullOrEmpty(i.PrimaryImagePath) && i.DefaultVideoStreamIndex.HasValue)
|
||||
.Take(1))
|
||||
{
|
||||
try
|
||||
{
|
||||
var chapters = _itemRepo.GetChapters(item.Id).ToList();
|
||||
|
||||
await _encodingManager.RefreshChapterImages(new ChapterImageRefreshOptions
|
||||
{
|
||||
SaveChapters = true,
|
||||
ExtractImages = true,
|
||||
Video = item,
|
||||
Chapters = chapters
|
||||
|
||||
}, CancellationToken.None);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error creating image for {0}", ex, item.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -133,7 +63,14 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
|
|||
{
|
||||
return new ITaskTrigger[]
|
||||
{
|
||||
new DailyTrigger { TimeOfDay = TimeSpan.FromHours(4) }
|
||||
new DailyTrigger
|
||||
{
|
||||
TimeOfDay = TimeSpan.FromHours(3),
|
||||
TaskOptions = new TaskExecutionOptions
|
||||
{
|
||||
MaxRuntimeMs = Convert.ToInt32(TimeSpan.FromHours(5).TotalMilliseconds)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user