kick off sync right after creating job

pull/702/head
Luke Pulverenti 10 years ago
parent d8d5dd4873
commit 87c23f145c

@ -1440,5 +1440,12 @@ namespace MediaBrowser.Model.ApiClient
/// <param name="request">The request.</param>
/// <returns>Task&lt;SyncDataResponse&gt;.</returns>
Task<SyncDataResponse> SyncData(SyncDataRequest request);
/// <summary>
/// Gets the synchronize job item file URL.
/// </summary>
/// <param name="id">The identifier.</param>
/// <returns>System.String.</returns>
string GetSyncJobItemFileUrl(string id);
}
}

@ -233,7 +233,8 @@ namespace MediaBrowser.Providers.Manager
using (var fs = _fileSystem.GetFileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, true))
{
await source.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, cancellationToken).ConfigureAwait(false);
await source.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, cancellationToken)
.ConfigureAwait(false);
}
if (_config.Configuration.SaveMetadataHidden)
@ -244,6 +245,11 @@ namespace MediaBrowser.Providers.Manager
file.Attributes |= FileAttributes.Hidden;
}
}
catch (UnauthorizedAccessException ex)
{
_logger.Error("Error saving image to {0}", ex, path);
throw new Exception(string.Format("Error saving image to {0}", path), ex);
}
finally
{
_libraryMonitor.ReportFileSystemChangeComplete(path, false);

@ -909,14 +909,6 @@ namespace MediaBrowser.Server.Implementations.Library
return obj as T;
}
/// <summary>
/// Creates an IBN item based on a given path
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="path">The path.</param>
/// <param name="name">The name.</param>
/// <returns>Task{``0}.</returns>
/// <exception cref="System.IO.IOException">Path not created: + path</exception>
private T CreateItemByName<T>(string path, string name, Guid id)
where T : BaseItem, new()
{
@ -942,7 +934,15 @@ namespace MediaBrowser.Server.Implementations.Library
if (!fileInfo.Exists)
{
fileInfo = Directory.CreateDirectory(path);
try
{
fileInfo = Directory.CreateDirectory(path);
}
catch (UnauthorizedAccessException ex)
{
_logger.Error("Error creating directory {0}", ex, path);
throw new Exception(string.Format("Error creating directory {0}", path), ex);
}
isNew = true;
}

@ -326,13 +326,17 @@ namespace MediaBrowser.Server.Implementations.Sync
Statuses = new List<SyncJobItemStatus> { SyncJobItemStatus.Queued, SyncJobItemStatus.Converting }
});
var jobItems = result.Items;
await SyncJobItems(result.Items, true, progress, cancellationToken).ConfigureAwait(false);
}
public async Task SyncJobItems(SyncJobItem[] items, bool enableConversion, IProgress<double> progress, CancellationToken cancellationToken)
{
var index = 0;
foreach (var item in jobItems)
foreach (var item in items)
{
double percent = index;
percent /= result.TotalRecordCount;
percent /= items.Length;
progress.Report(100 * percent);
@ -341,7 +345,7 @@ namespace MediaBrowser.Server.Implementations.Sync
var innerProgress = new ActionableProgress<double>();
var job = _syncRepo.GetJob(item.JobId);
await ProcessJobItem(job, item, innerProgress, cancellationToken).ConfigureAwait(false);
await ProcessJobItem(job, item, enableConversion, innerProgress, cancellationToken).ConfigureAwait(false);
job = _syncRepo.GetJob(item.JobId);
await UpdateJobStatus(job).ConfigureAwait(false);
@ -350,7 +354,7 @@ namespace MediaBrowser.Server.Implementations.Sync
}
}
private async Task ProcessJobItem(SyncJob job, SyncJobItem jobItem, IProgress<double> progress, CancellationToken cancellationToken)
private async Task ProcessJobItem(SyncJob job, SyncJobItem jobItem, bool enableConversion, IProgress<double> progress, CancellationToken cancellationToken)
{
var item = _libraryManager.GetItemById(jobItem.ItemId);
if (item == null)
@ -378,12 +382,12 @@ namespace MediaBrowser.Server.Implementations.Sync
var video = item as Video;
if (video != null)
{
await Sync(jobItem, video, user, deviceProfile, progress, cancellationToken).ConfigureAwait(false);
await Sync(jobItem, video, user, deviceProfile, enableConversion, progress, cancellationToken).ConfigureAwait(false);
}
else if (item is Audio)
{
await Sync(jobItem, (Audio)item, user, deviceProfile, progress, cancellationToken).ConfigureAwait(false);
await Sync(jobItem, (Audio)item, user, deviceProfile, enableConversion, progress, cancellationToken).ConfigureAwait(false);
}
else if (item is Photo)
@ -397,7 +401,7 @@ namespace MediaBrowser.Server.Implementations.Sync
}
}
private async Task Sync(SyncJobItem jobItem, Video item, User user, DeviceProfile profile, IProgress<double> progress, CancellationToken cancellationToken)
private async Task Sync(SyncJobItem jobItem, Video item, User user, DeviceProfile profile, bool enableConversion, IProgress<double> progress, CancellationToken cancellationToken)
{
var options = new VideoOptions
{
@ -415,6 +419,11 @@ namespace MediaBrowser.Server.Implementations.Sync
if (streamInfo.PlayMethod == PlayMethod.Transcode)
{
if (!enableConversion)
{
return;
}
jobItem.Status = SyncJobItemStatus.Converting;
jobItem.RequiresConversion = true;
await _syncRepo.Update(jobItem).ConfigureAwait(false);
@ -463,7 +472,7 @@ namespace MediaBrowser.Server.Implementations.Sync
await _syncRepo.Update(jobItem).ConfigureAwait(false);
}
private async Task Sync(SyncJobItem jobItem, Audio item, User user, DeviceProfile profile, IProgress<double> progress, CancellationToken cancellationToken)
private async Task Sync(SyncJobItem jobItem, Audio item, User user, DeviceProfile profile, bool enableConversion, IProgress<double> progress, CancellationToken cancellationToken)
{
var options = new AudioOptions
{
@ -481,6 +490,11 @@ namespace MediaBrowser.Server.Implementations.Sync
if (streamInfo.PlayMethod == PlayMethod.Transcode)
{
if (!enableConversion)
{
return;
}
jobItem.Status = SyncJobItemStatus.Converting;
jobItem.RequiresConversion = true;
await _syncRepo.Update(jobItem).ConfigureAwait(false);

@ -23,6 +23,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Server.Implementations.Sync
@ -126,6 +127,16 @@ namespace MediaBrowser.Server.Implementations.Sync
await _repo.Create(job).ConfigureAwait(false);
await processor.EnsureJobItems(job).ConfigureAwait(false);
// If it already has a converting status then is must have been aborted during conversion
var jobItemsResult = _repo.GetJobItems(new SyncJobItemQuery
{
Statuses = new List<SyncJobItemStatus> { SyncJobItemStatus.Queued, SyncJobItemStatus.Converting },
JobId = jobId
});
await processor.SyncJobItems(jobItemsResult.Items, false, new Progress<double>(), CancellationToken.None)
.ConfigureAwait(false);
return new SyncJobCreationResult
{

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Common.Internal</id>
<version>3.0.540</version>
<version>3.0.541</version>
<title>MediaBrowser.Common.Internal</title>
<authors>Luke</authors>
<owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption.</description>
<copyright>Copyright © Media Browser 2013</copyright>
<dependencies>
<dependency id="MediaBrowser.Common" version="3.0.540" />
<dependency id="MediaBrowser.Common" version="3.0.541" />
<dependency id="NLog" version="3.1.0.0" />
<dependency id="SimpleInjector" version="2.6.1" />
</dependencies>

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Common</id>
<version>3.0.540</version>
<version>3.0.541</version>
<title>MediaBrowser.Common</title>
<authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners>

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Model.Signed</id>
<version>3.0.540</version>
<version>3.0.541</version>
<title>MediaBrowser.Model - Signed Edition</title>
<authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners>

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>MediaBrowser.Server.Core</id>
<version>3.0.540</version>
<version>3.0.541</version>
<title>Media Browser.Server.Core</title>
<authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains core components required to build plugins for Media Browser Server.</description>
<copyright>Copyright © Media Browser 2013</copyright>
<dependencies>
<dependency id="MediaBrowser.Common" version="3.0.540" />
<dependency id="MediaBrowser.Common" version="3.0.541" />
</dependencies>
</metadata>
<files>

Loading…
Cancel
Save