mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-20 17:14:42 +01:00
sync updates
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using System.Globalization;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Common.Progress;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
@@ -361,11 +360,20 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
var innerProgress = new ActionableProgress<double>();
|
||||
innerProgress.RegisterAction(p => progress.Report(startingPercent + (percentPerItem * p)));
|
||||
|
||||
var job = _syncRepo.GetJob(item.JobId);
|
||||
await ProcessJobItem(job, item, enableConversion, innerProgress, cancellationToken).ConfigureAwait(false);
|
||||
// Pull it fresh from the db just to make sure it wasn't deleted or cancelled while another item was converting
|
||||
var jobItem = enableConversion ? _syncRepo.GetJobItem(item.Id) : item;
|
||||
|
||||
job = _syncRepo.GetJob(item.JobId);
|
||||
await UpdateJobStatus(job).ConfigureAwait(false);
|
||||
if (jobItem != null)
|
||||
{
|
||||
var job = _syncRepo.GetJob(jobItem.JobId);
|
||||
if (jobItem.Status != SyncJobItemStatus.Cancelled)
|
||||
{
|
||||
await ProcessJobItem(job, jobItem, enableConversion, innerProgress, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
job = _syncRepo.GetJob(jobItem.JobId);
|
||||
await UpdateJobStatus(job).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
numComplete++;
|
||||
double percent = numComplete;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using MediaBrowser.Common;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.Events;
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Controller.Channels;
|
||||
@@ -16,6 +17,7 @@ using MediaBrowser.Controller.TV;
|
||||
using MediaBrowser.Model.Dlna;
|
||||
using MediaBrowser.Model.Dto;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Events;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Querying;
|
||||
using MediaBrowser.Model.Sync;
|
||||
@@ -47,6 +49,9 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
|
||||
private ISyncProvider[] _providers = { };
|
||||
|
||||
public event EventHandler<GenericEventArgs<SyncJob>> SyncJobCreated;
|
||||
public event EventHandler<GenericEventArgs<SyncJob>> SyncJobCancelled;
|
||||
|
||||
public SyncManager(ILibraryManager libraryManager, ISyncRepository repo, IImageProcessor imageProcessor, ILogger logger, IUserManager userManager, Func<IDtoService> dtoService, IApplicationHost appHost, ITVSeriesManager tvSeriesManager, Func<IMediaEncoder> mediaEncoder, IFileSystem fileSystem, Func<ISubtitleEncoder> subtitleEncoder, IConfigurationManager config)
|
||||
{
|
||||
_libraryManager = libraryManager;
|
||||
@@ -144,6 +149,15 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
await processor.SyncJobItems(jobItemsResult.Items, false, new Progress<double>(), CancellationToken.None)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (SyncJobCreated != null)
|
||||
{
|
||||
EventHelper.FireEventIfNotNull(SyncJobCreated, this, new GenericEventArgs<SyncJob>
|
||||
{
|
||||
Argument = job
|
||||
|
||||
}, _logger);
|
||||
}
|
||||
|
||||
return new SyncJobCreationResult
|
||||
{
|
||||
Job = GetJob(jobId)
|
||||
@@ -275,9 +289,25 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
}
|
||||
}
|
||||
|
||||
public Task CancelJob(string id)
|
||||
public async Task CancelJob(string id)
|
||||
{
|
||||
return _repo.DeleteJob(id);
|
||||
var job = GetJob(id);
|
||||
|
||||
if (job == null)
|
||||
{
|
||||
throw new ArgumentException("Job not found.");
|
||||
}
|
||||
|
||||
await _repo.DeleteJob(id).ConfigureAwait(false);
|
||||
|
||||
if (SyncJobCancelled != null)
|
||||
{
|
||||
EventHelper.FireEventIfNotNull(SyncJobCancelled, this, new GenericEventArgs<SyncJob>
|
||||
{
|
||||
Argument = job
|
||||
|
||||
}, _logger);
|
||||
}
|
||||
}
|
||||
|
||||
public SyncJob GetJob(string id)
|
||||
@@ -496,7 +526,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
.FirstOrDefault(i => string.Equals(i.Id, jobItem.MediaSourceId));
|
||||
|
||||
syncedItem.Item.MediaSources = new List<MediaSourceInfo>();
|
||||
|
||||
|
||||
// This will be null for items that are not audio/video
|
||||
if (mediaSource == null)
|
||||
{
|
||||
@@ -545,7 +575,12 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
var job = _repo.GetJob(jobItem.JobId);
|
||||
var user = _userManager.GetUserById(job.UserId);
|
||||
|
||||
if (user == null)
|
||||
if (jobItem.IsMarkedForRemoval)
|
||||
{
|
||||
// Tell the device to remove it since it has been marked for removal
|
||||
response.ItemIdsToRemove.Add(jobItem.ItemId);
|
||||
}
|
||||
else if (user == null)
|
||||
{
|
||||
// Tell the device to remove it since the user is gone now
|
||||
response.ItemIdsToRemove.Add(jobItem.ItemId);
|
||||
@@ -609,5 +644,45 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task ReEnableJobItem(string id)
|
||||
{
|
||||
var jobItem = _repo.GetJobItem(id);
|
||||
|
||||
if (jobItem.Status != SyncJobItemStatus.Failed && jobItem.Status != SyncJobItemStatus.Cancelled)
|
||||
{
|
||||
throw new ArgumentException("Operation is not valid for this job item");
|
||||
}
|
||||
|
||||
jobItem.Status = SyncJobItemStatus.Queued;
|
||||
jobItem.Progress = 0;
|
||||
jobItem.IsMarkedForRemoval = false;
|
||||
|
||||
await _repo.Update(jobItem).ConfigureAwait(false);
|
||||
|
||||
var processor = GetSyncJobProcessor();
|
||||
|
||||
await processor.UpdateJobStatus(jobItem.JobId).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task CancelJobItem(string id)
|
||||
{
|
||||
var jobItem = _repo.GetJobItem(id);
|
||||
|
||||
if (jobItem.Status != SyncJobItemStatus.Queued && jobItem.Status != SyncJobItemStatus.Transferring && jobItem.Status != SyncJobItemStatus.Converting)
|
||||
{
|
||||
throw new ArgumentException("Operation is not valid for this job item");
|
||||
}
|
||||
|
||||
jobItem.Status = SyncJobItemStatus.Cancelled;
|
||||
jobItem.Progress = 0;
|
||||
jobItem.IsMarkedForRemoval = true;
|
||||
|
||||
await _repo.Update(jobItem).ConfigureAwait(false);
|
||||
|
||||
var processor = GetSyncJobProcessor();
|
||||
|
||||
await processor.UpdateJobStatus(jobItem.JobId).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
|
||||
public async Task Initialize()
|
||||
{
|
||||
var dbFile = Path.Combine(_appPaths.DataPath, "sync12.db");
|
||||
var dbFile = Path.Combine(_appPaths.DataPath, "sync13.db");
|
||||
|
||||
_connection = await SqliteExtensions.ConnectToDb(dbFile, _logger).ConfigureAwait(false);
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
"create table if not exists SyncJobs (Id GUID PRIMARY KEY, TargetId TEXT NOT NULL, Name TEXT NOT NULL, Quality TEXT NOT NULL, Status TEXT NOT NULL, Progress FLOAT, UserId TEXT NOT NULL, ItemIds TEXT NOT NULL, Category TEXT, ParentId TEXT, UnwatchedOnly BIT, ItemLimit INT, SyncNewContent BIT, DateCreated DateTime, DateLastModified DateTime, ItemCount int)",
|
||||
"create index if not exists idx_SyncJobs on SyncJobs(Id)",
|
||||
|
||||
"create table if not exists SyncJobItems (Id GUID PRIMARY KEY, ItemId TEXT, ItemName TEXT, MediaSourceId TEXT, JobId TEXT, TemporaryPath TEXT, OutputPath TEXT, Status TEXT, TargetId TEXT, DateCreated DateTime, Progress FLOAT, AdditionalFiles TEXT, MediaSource TEXT)",
|
||||
"create table if not exists SyncJobItems (Id GUID PRIMARY KEY, ItemId TEXT, ItemName TEXT, MediaSourceId TEXT, JobId TEXT, TemporaryPath TEXT, OutputPath TEXT, Status TEXT, TargetId TEXT, DateCreated DateTime, Progress FLOAT, AdditionalFiles TEXT, MediaSource TEXT, IsMarkedForRemoval BIT)",
|
||||
"create index if not exists idx_SyncJobItems on SyncJobs(Id)",
|
||||
|
||||
//pragmas
|
||||
@@ -95,7 +95,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
_saveJobCommand.Parameters.Add(_saveJobCommand, "@ItemCount");
|
||||
|
||||
_saveJobItemCommand = _connection.CreateCommand();
|
||||
_saveJobItemCommand.CommandText = "replace into SyncJobItems (Id, ItemId, ItemName, MediaSourceId, JobId, TemporaryPath, OutputPath, Status, TargetId, DateCreated, Progress, AdditionalFiles, MediaSource) values (@Id, @ItemId, @ItemName, @MediaSourceId, @JobId, @TemporaryPath, @OutputPath, @Status, @TargetId, @DateCreated, @Progress, @AdditionalFiles, @MediaSource)";
|
||||
_saveJobItemCommand.CommandText = "replace into SyncJobItems (Id, ItemId, ItemName, MediaSourceId, JobId, TemporaryPath, OutputPath, Status, TargetId, DateCreated, Progress, AdditionalFiles, MediaSource, IsMarkedForRemoval) values (@Id, @ItemId, @ItemName, @MediaSourceId, @JobId, @TemporaryPath, @OutputPath, @Status, @TargetId, @DateCreated, @Progress, @AdditionalFiles, @MediaSource, @IsMarkedForRemoval)";
|
||||
|
||||
_saveJobItemCommand.Parameters.Add(_saveJobItemCommand, "@Id");
|
||||
_saveJobItemCommand.Parameters.Add(_saveJobItemCommand, "@ItemId");
|
||||
@@ -110,10 +110,11 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
_saveJobItemCommand.Parameters.Add(_saveJobItemCommand, "@Progress");
|
||||
_saveJobItemCommand.Parameters.Add(_saveJobItemCommand, "@AdditionalFiles");
|
||||
_saveJobItemCommand.Parameters.Add(_saveJobItemCommand, "@MediaSource");
|
||||
_saveJobItemCommand.Parameters.Add(_saveJobItemCommand, "@IsMarkedForRemoval");
|
||||
}
|
||||
|
||||
private const string BaseJobSelectText = "select Id, TargetId, Name, Quality, Status, Progress, UserId, ItemIds, Category, ParentId, UnwatchedOnly, ItemLimit, SyncNewContent, DateCreated, DateLastModified, ItemCount from SyncJobs";
|
||||
private const string BaseJobItemSelectText = "select Id, ItemId, ItemName, MediaSourceId, JobId, TemporaryPath, OutputPath, Status, TargetId, DateCreated, Progress, AdditionalFiles, MediaSource from SyncJobItems";
|
||||
private const string BaseJobItemSelectText = "select Id, ItemId, ItemName, MediaSourceId, JobId, TemporaryPath, OutputPath, Status, TargetId, DateCreated, Progress, AdditionalFiles, MediaSource, IsMarkedForRemoval from SyncJobItems";
|
||||
|
||||
public SyncJob GetJob(string id)
|
||||
{
|
||||
@@ -572,6 +573,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
_saveJobItemCommand.GetParameter(index++).Value = jobItem.Progress;
|
||||
_saveJobItemCommand.GetParameter(index++).Value = _json.SerializeToString(jobItem.AdditionalFiles);
|
||||
_saveJobItemCommand.GetParameter(index++).Value = jobItem.MediaSource == null ? null : _json.SerializeToString(jobItem.MediaSource);
|
||||
_saveJobItemCommand.GetParameter(index++).Value = jobItem.IsMarkedForRemoval;
|
||||
|
||||
_saveJobItemCommand.Transaction = transaction;
|
||||
|
||||
@@ -673,6 +675,8 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
}
|
||||
}
|
||||
|
||||
info.IsMarkedForRemoval = reader.GetBoolean(13);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user