private void LoadPendingImportJobs() { if (_status != Status.Shutdown) { ServiceRegistration.Get <ILogger>().Warn("ImporterWorker: ImportJobs can only be loaded if the ImporterWorker is in status shutdown."); } else { var settings = ServiceRegistration.Get <ISettingsManager>().Load <PendingResourcesSettings>(); if (settings.PendingImportJobs.Count > 0) { int numberOfSuccessfullyRestoredImportJobs = 0; foreach (var importJob in settings.PendingImportJobs) { try { var importJobController = new ImportJobController(importJob, Interlocked.Increment(ref _numberOfLastImportJob), this); numberOfSuccessfullyRestoredImportJobs++; _importJobControllers[importJob.ImportJobInformation] = importJobController; } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Error("ImporterWorker: Error while restoring ImportJob from disk", ex); } } ServiceRegistration.Get <ILogger>().Info("ImporterWorker: {0} persisted ImportJobs restored from disk", numberOfSuccessfullyRestoredImportJobs); } } }
/// <summary> /// Initializes this PendingImportResource after deserialization /// </summary> /// <remarks> /// This method must be called onces after this PendingImportResource has been deserialized. /// It must not be called in any other circumstances. /// </remarks> /// <param name="parentImportJobController">ImportJobController this PendingImportResource belongs to</param> public void InitializeAfterDeserialization(ImportJobController parentImportJobController) { _parentImportJobController = parentImportJobController; _pendingImportResourceNumber = _parentImportJobController.GetNumberOfNextPendingImportResource(); _isValid = true; _parentImportJobController.RegisterPendingImportResource(this); }
private void DoScheduleImport(ImportJobInformation importJobInformation) { if (_status == Status.Shutdown) { ServiceRegistration.Get <ILogger>().Error("ImporterWorker: Scheduling of an ImportJob was requested although status was neither 'Activated' nor 'Suspended' but 'Shutdown'"); return; } // For now we always set this to active to make it look like the old ImporterWorker // ToDo: Remove this and all usages of ImportJobInformation.State importJobInformation.State = ImportJobState.Active; // if the ImportJob to be scheduled is the same as or contains an // already running ImportJob, cancel the already running ImportJob // and schedule this one var jobsToBeCancelled = new HashSet <ImportJobController>(); foreach (var kvp in _importJobControllers) { if (importJobInformation >= kvp.Key) { ServiceRegistration.Get <ILogger>().Info("ImporterWorker: {0} is contained in or the same as the ImportJob which is currently being scheduled. Canceling {1}", kvp.Value, kvp.Value); kvp.Value.Cancel(); jobsToBeCancelled.Add(kvp.Value); } } // We need to wait here until the canceled ImportJobs are removed from _importJobControllers // otherwise we run into trouble when the ImportJobs equal each other because then they // have the same key in _importJobControllers. Task.WhenAll(jobsToBeCancelled.Select(controller => controller.Completion)).Wait(); foreach (var controller in jobsToBeCancelled) { controller.Dispose(); } //Set updated media items to changed _mediaBrowsing?.MarkUpdatableMediaItems(); var importJobController = new ImportJobController(new ImportJobNewGen(importJobInformation, null), Interlocked.Increment(ref _numberOfLastImportJob), this); _importJobControllers[importJobInformation] = importJobController; ServiceRegistration.Get <ILogger>().Info("ImporterWorker: Scheduled {0} ({1}) (Path ='{2}', ImportJobType='{3}', IncludeSubdirectories='{4}')", importJobController, _status, importJobInformation.BasePath, importJobInformation.JobType, importJobInformation.IncludeSubDirectories); ImporterWorkerMessaging.SendImportMessage(ImporterWorkerMessaging.MessageType.ImportScheduled, importJobInformation.BasePath, importJobInformation.JobType); if (_status == Status.Activated) { importJobController.Activate(_mediaBrowsing, _importResultHandler); } }
private DateTime _dateOfLastImport; // only valid for refresh imports #endregion #region Constructor public PendingImportResourceNewGen(ResourcePath parentDirectory, IFileSystemResourceAccessor resourceAccessor, String currentBlock, ImportJobController parentImportJobController, Guid?parentDirectoryId = null, Guid?mediaItemId = null) { _parentDirectoryId = parentDirectoryId; _mediaItemId = mediaItemId; _parentDirectoryResourcePathString = (parentDirectory == null) ? "" : parentDirectory.Serialize(); _resourceAccessor = resourceAccessor; _currentBlock = currentBlock; _parentImportJobController = parentImportJobController; _pendingImportResourceNumber = _parentImportJobController.GetNumberOfNextPendingImportResource(); _isValid = (_resourceAccessor != null); _parentImportJobController.RegisterPendingImportResource(this); }
private DateTime _dateOfLastImport; // only valid for refresh imports #endregion #region Constructor public PendingImportResourceNewGen(ResourcePath parentDirectory, IFileSystemResourceAccessor resourceAccessor, String currentBlock, ImportJobController parentImportJobController, Guid? parentDirectoryId = null, Guid? mediaItemId = null) { _parentDirectoryId = parentDirectoryId; _mediaItemId = mediaItemId; _parentDirectoryResourcePathString = (parentDirectory == null) ? "" : parentDirectory.Serialize(); _resourceAccessor = resourceAccessor; _currentBlock = currentBlock; _parentImportJobController = parentImportJobController; _pendingImportResourceNumber = _parentImportJobController.GetNumberOfNextPendingImportResource(); _isValid = (_resourceAccessor != null); _parentImportJobController.RegisterPendingImportResource(this); }
private void LoadPendingImportJobs() { if (_status != Status.Shutdown) ServiceRegistration.Get<ILogger>().Warn("ImporterWorker: ImportJobs can only be loaded if the ImporterWorker is in status shutdown."); else { var settings = ServiceRegistration.Get<ISettingsManager>().Load<PendingResourcesSettings>(); if (settings.PendingImportJobs.Count > 0) { int numberOfSuccessfullyRestoredImportJobs = 0; foreach (var importJob in settings.PendingImportJobs) { try { var importJobController = new ImportJobController(importJob, Interlocked.Increment(ref _numberOfLastImportJob), this); numberOfSuccessfullyRestoredImportJobs++; _importJobControllers[importJob.ImportJobInformation] = importJobController; } catch (Exception ex) { ServiceRegistration.Get<ILogger>().Error("ImporterWorker: Error while restoring ImportJob from disk", ex); } } ServiceRegistration.Get<ILogger>().Info("ImporterWorker: {0} persisted ImportJobs restored from disk", numberOfSuccessfullyRestoredImportJobs); } } }
private void DoScheduleImport(ImportJobInformation importJobInformation) { if (_status == Status.Shutdown) { ServiceRegistration.Get<ILogger>().Error("ImporterWorker: Scheduling of an ImportJob was requested although status was neither 'Activated' nor 'Suspended' but 'Shutdown'"); return; } // For now we always set this to active to make it look like the old ImporterWorker // ToDo: Remove this and all usages of ImportJobInformation.State importJobInformation.State = ImportJobState.Active; // if the ImportJob to be scheduled is the same as or contains an // already running ImportJob, cancel the already running ImportJob // and schedule this one var jobsToBeCancelled = new HashSet<ImportJobController>(); foreach (var kvp in _importJobControllers) if (importJobInformation >= kvp.Key) { ServiceRegistration.Get<ILogger>().Info("ImporterWorker: {0} is contained in or the same as the ImportJob which is currently being scheduled. Canceling {1}", kvp.Value, kvp.Value); kvp.Value.Cancel(); jobsToBeCancelled.Add(kvp.Value); } // We need to wait here until the canceled ImportJobs are removed from _importJobControllers // otherwise we run into trouble when the ImportJobs equal each other because then they // have the same key in _importJobControllers. Task.WhenAll(jobsToBeCancelled.Select(controller => controller.Completion)).Wait(); foreach (var controller in jobsToBeCancelled) controller.Dispose(); var importJobController = new ImportJobController(new ImportJobNewGen(importJobInformation, null), Interlocked.Increment(ref _numberOfLastImportJob), this); _importJobControllers[importJobInformation] = importJobController; ServiceRegistration.Get<ILogger>().Info("ImporterWorker: Scheduled {0} ({1}) (Path ='{2}', ImportJobType='{3}', IncludeSubdirectories='{4}')", importJobController, _status, importJobInformation.BasePath, importJobInformation.JobType, importJobInformation.IncludeSubDirectories); ImporterWorkerMessaging.SendImportMessage(ImporterWorkerMessaging.MessageType.ImportScheduled, importJobInformation.BasePath, importJobInformation.JobType); if (_status == Status.Activated) importJobController.Activate(_mediaBrowsing, _importResultHandler); }