/// <summary> /// /// </summary> /// <param name="reason"></param> /// <param name="key"></param> /// <exception cref="InvalidStudyStateOperationException">Study is in a state that reprocessing is not allowed</exception> public void ReprocessStudy(String reason, ServerEntityKey key) { StudyStorageAdaptor adaptor = new StudyStorageAdaptor(); StudyStorage storage = adaptor.Get(key); StudyStorageLocation storageLocation = StudyStorageLocation.FindStorageLocations(storage)[0]; StudyReprocessor reprocessor = new StudyReprocessor(); reprocessor.ReprocessStudy(reason, storageLocation, Platform.Time); }
private void ReprocessStudy(StudyStorageLocation restoredLocation, string reason) { var reprocessor = new StudyReprocessor(); String reprocessReason = String.Format("Restore Validation Error: {0}", reason); reprocessor.ReprocessStudy(reprocessReason, restoredLocation, Platform.Time); string message = string.Format("Study {0} has been restored but failed the validation. Reprocess Study has been triggered. Reason for validation failure: {1}", restoredLocation.StudyInstanceUid, reason); Platform.Log(LogLevel.Warn, message); ServerPlatform.Alert(AlertCategory.Application, AlertLevel.Informational, "Restore", 0, null, TimeSpan.Zero, message); }
public bool ReprocessWorkQueueItem(WorkQueue item) { // #10620: Get a list of remaining WorkQueueUids which need to be reprocess // Note: currently only WorkQueueUIDs in failed StudyProcess will be reprocessed var remainingWorkQueueUidPaths = item.GetAllWorkQueueUidPaths(); IPersistentStore store = PersistentStoreRegistry.GetDefaultStore(); using (IUpdateContext ctx = store.OpenUpdateContext(UpdateContextSyncMode.Flush)) { // delete current workqueue IWorkQueueUidEntityBroker uidBroker = ctx.GetBroker <IWorkQueueUidEntityBroker>(); WorkQueueUidSelectCriteria criteria = new WorkQueueUidSelectCriteria(); criteria.WorkQueueKey.EqualTo(item.GetKey()); if (uidBroker.Delete(criteria) >= 0) { IWorkQueueEntityBroker workQueueBroker = ctx.GetBroker <IWorkQueueEntityBroker>(); if (workQueueBroker.Delete(item.GetKey())) { IList <StudyStorageLocation> locations = item.LoadStudyLocations(ctx); if (locations != null && locations.Count > 0) { StudyReprocessor reprocessor = new StudyReprocessor(); String reason = String.Format("User reprocesses failed {0}", item.WorkQueueTypeEnum); WorkQueue reprocessEntry = reprocessor.ReprocessStudy(ctx, reason, locations[0], remainingWorkQueueUidPaths, Platform.Time); if (reprocessEntry != null) { ctx.Commit(); } return(reprocessEntry != null); } } } } return(false); }
/// <summary> /// Do the actual rebuild. On error, will attempt to reprocess the study. /// </summary> public void RebuildXml() { string rootStudyPath = _location.GetStudyPath(); try { using (ServerCommandProcessor processor = new ServerCommandProcessor("Rebuild XML")) { var command = new RebuildStudyXmlCommand(_location.StudyInstanceUid, rootStudyPath); processor.AddCommand(command); var updateCommand = new UpdateStudySizeInDBCommand(_location, command); processor.AddCommand(updateCommand); if (!processor.Execute()) { throw new ApplicationException(processor.FailureReason, processor.FailureException); } Study theStudy = _location.Study; if (theStudy.NumberOfStudyRelatedInstances != command.StudyXml.NumberOfStudyRelatedInstances) { // We rebuilt, but the counts don't match. throw new StudyIntegrityValidationFailure(ValidationErrors.InconsistentObjectCount, new ValidationStudyInfo(theStudy, _location.ServerPartition), string.Format( "Database study count {0} does not match study xml {1}", theStudy.NumberOfStudyRelatedInstances, command.StudyXml.NumberOfStudyRelatedInstances)); } Platform.Log(LogLevel.Info, "Completed reprocessing Study XML file for study {0}", _location.StudyInstanceUid); } } catch (Exception e) { Platform.Log(LogLevel.Error, e, "Unexpected error when rebuilding study XML for directory: {0}", _location.FilesystemPath); StudyReprocessor reprocessor = new StudyReprocessor(); try { WorkQueue reprocessEntry = reprocessor.ReprocessStudy("Rebuild StudyXml", _location, Platform.Time); if (reprocessEntry != null) { Platform.Log(LogLevel.Error, "Failure attempting to reprocess study: {0}", _location.StudyInstanceUid); } else { Platform.Log(LogLevel.Error, "Inserted reprocess request for study: {0}", _location.StudyInstanceUid); } } catch (InvalidStudyStateOperationException ex) { Platform.Log(LogLevel.Error, "Failure attempting to reprocess study {0}: {1}", _location.StudyInstanceUid, ex.Message); } } }