private void ReinsertFilesystemQueue() { using (IUpdateContext updateContext = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush)) { IWorkQueueUidEntityBroker broker = updateContext.GetBroker <IWorkQueueUidEntityBroker>(); WorkQueueUidSelectCriteria workQueueUidCriteria = new WorkQueueUidSelectCriteria(); workQueueUidCriteria.WorkQueueKey.EqualTo(WorkQueueItem.Key); broker.Delete(workQueueUidCriteria); FilesystemQueueInsertParameters parms = new FilesystemQueueInsertParameters { FilesystemQueueTypeEnum = FilesystemQueueTypeEnum.TierMigrate, ScheduledTime = Platform.Time.AddMinutes(10), StudyStorageKey = WorkQueueItem.StudyStorageKey, FilesystemKey = StorageLocation.FilesystemKey }; IInsertFilesystemQueue insertQueue = updateContext.GetBroker <IInsertFilesystemQueue>(); if (false == insertQueue.Execute(parms)) { Platform.Log(LogLevel.Error, "Unexpected failure inserting FilesystemQueue entry"); } else { updateContext.Commit(); } } }
public static void FailUid(WorkQueueUid sop, bool retry) { using (IUpdateContext updateContext = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush)) { IWorkQueueUidEntityBroker uidUpdateBroker = updateContext.GetBroker <IWorkQueueUidEntityBroker>(); WorkQueueUidUpdateColumns columns = new WorkQueueUidUpdateColumns(); if (!retry) { columns.Failed = true; } else { if (sop.FailureCount >= ImageServerCommonConfiguration.WorkQueueMaxFailureCount) { columns.Failed = true; } else { columns.FailureCount = ++sop.FailureCount; } } uidUpdateBroker.Update(sop.GetKey(), columns); updateContext.Commit(); } }
private void ReinsertFilesystemQueue(TimeSpan delay) { using (IUpdateContext updateContext = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush)) { IWorkQueueUidEntityBroker broker = updateContext.GetBroker <IWorkQueueUidEntityBroker>(); WorkQueueUidSelectCriteria workQueueUidCriteria = new WorkQueueUidSelectCriteria(); workQueueUidCriteria.WorkQueueKey.EqualTo(WorkQueueItem.Key); broker.Delete(workQueueUidCriteria); FilesystemQueueInsertParameters parms = new FilesystemQueueInsertParameters(); parms.FilesystemQueueTypeEnum = CompressTransferSyntax.LosslessCompressed ? FilesystemQueueTypeEnum.LosslessCompress : FilesystemQueueTypeEnum.LossyCompress; parms.ScheduledTime = Platform.Time + delay; parms.StudyStorageKey = WorkQueueItem.StudyStorageKey; parms.FilesystemKey = StorageLocation.FilesystemKey; parms.QueueXml = WorkQueueItem.Data; IInsertFilesystemQueue insertQueue = updateContext.GetBroker <IInsertFilesystemQueue>(); if (false == insertQueue.Execute(parms)) { Platform.Log(LogLevel.Error, "Unexpected failure inserting FilesystemQueue entry"); } else { updateContext.Commit(); } } }
/// <summary> /// Finds all <see cref="WorkQueueUids"/> this item. /// </summary> /// <param name="item"></param> /// <returns></returns> public static IList <WorkQueueUid> LoadAllWorkQueueUid(this WorkQueue item) { using (var readctx = PersistentStoreRegistry.GetDefaultStore().OpenReadContext()) { IWorkQueueUidEntityBroker broker = readctx.GetBroker <IWorkQueueUidEntityBroker>(); var criteria = new WorkQueueUidSelectCriteria(); criteria.WorkQueueKey.EqualTo(item.Key); return(broker.Find(criteria)); } }
private IList <WorkQueueUid> LoadAllWorkQueueUids() { using (IReadContext context = PersistentStoreRegistry.GetDefaultStore().OpenReadContext()) { IWorkQueueUidEntityBroker broker = context.GetBroker <IWorkQueueUidEntityBroker>(); WorkQueueUidSelectCriteria criteria = new WorkQueueUidSelectCriteria(); criteria.WorkQueueKey.EqualTo(WorkQueueItem.Key); return(broker.Find(criteria)); } }
/// <summary> /// Delete the Work Queue record from the system. /// </summary> /// <param name="context"></param> /// <returns></returns> public bool Delete(IPersistenceContext context) { IWorkQueueUidEntityBroker workQueueUidBroker = context.GetBroker <IWorkQueueUidEntityBroker>(); WorkQueueUidSelectCriteria criteria = new WorkQueueUidSelectCriteria(); criteria.WorkQueueKey.EqualTo(GetKey()); workQueueUidBroker.Delete(criteria); IWorkQueueEntityBroker workQueueBroker = context.GetBroker <IWorkQueueEntityBroker>(); return(workQueueBroker.Delete(GetKey())); }
/// <summary> /// Load all of the instances in a given <see cref="StudyXml"/> file into the component for sending. /// </summary> /// <param name="studyXml">The <see cref="StudyXml"/> file to load from</param> /// <param name="context"></param> /// <param name="workQueueKey"></param> protected static void InsertWorkQueueUidFromStudyXml(StudyXml studyXml, IUpdateContext context, ServerEntityKey workQueueKey) { foreach (SeriesXml seriesXml in studyXml) { foreach (InstanceXml instanceXml in seriesXml) { WorkQueueUidUpdateColumns updateColumns = new WorkQueueUidUpdateColumns(); updateColumns.Duplicate = false; updateColumns.Failed = false; updateColumns.SeriesInstanceUid = seriesXml.SeriesInstanceUid; updateColumns.SopInstanceUid = instanceXml.SopInstanceUid; updateColumns.WorkQueueKey = workQueueKey; IWorkQueueUidEntityBroker broker = context.GetBroker <IWorkQueueUidEntityBroker>(); broker.Insert(updateColumns); } } }
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> /// Inserts work queue entry to process the duplicates. /// </summary> /// <param name="entryKey"><see cref="ServerEntityKey"/> of the <see cref="StudyIntegrityQueue"/> entry that has <see cref="StudyIntegrityReasonEnum"/> equal to <see cref="StudyIntegrityReasonEnum.Duplicate"/> </param> /// <param name="action"></param> public void Process(ServerEntityKey entryKey, ProcessDuplicateAction action) { DuplicateSopReceivedQueue entry = DuplicateSopReceivedQueue.Load(HttpContextData.Current.ReadContext, entryKey); Platform.CheckTrue(entry.StudyIntegrityReasonEnum == StudyIntegrityReasonEnum.Duplicate, "Invalid type of entry"); IList <StudyIntegrityQueueUid> uids = LoadDuplicateSopUid(entry); using (IUpdateContext context = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush)) { ProcessDuplicateQueueEntryQueueData data = new ProcessDuplicateQueueEntryQueueData { Action = action, DuplicateSopFolder = entry.GetFolderPath(context), UserName = ServerHelper.CurrentUserName, }; LockStudyParameters lockParms = new LockStudyParameters { QueueStudyStateEnum = QueueStudyStateEnum.ReconcileScheduled, StudyStorageKey = entry.StudyStorageKey }; ILockStudy lockBbroker = context.GetBroker <ILockStudy>(); lockBbroker.Execute(lockParms); if (!lockParms.Successful) { throw new ApplicationException(lockParms.FailureReason); } IWorkQueueProcessDuplicateSopBroker broker = context.GetBroker <IWorkQueueProcessDuplicateSopBroker>(); WorkQueueProcessDuplicateSopUpdateColumns columns = new WorkQueueProcessDuplicateSopUpdateColumns { Data = XmlUtils.SerializeAsXmlDoc(data), GroupID = entry.GroupID, ScheduledTime = Platform.Time, ExpirationTime = Platform.Time.Add(TimeSpan.FromMinutes(15)), ServerPartitionKey = entry.ServerPartitionKey, WorkQueuePriorityEnum = WorkQueuePriorityEnum.Medium, StudyStorageKey = entry.StudyStorageKey, WorkQueueStatusEnum = WorkQueueStatusEnum.Pending }; WorkQueueProcessDuplicateSop processDuplicateWorkQueueEntry = broker.Insert(columns); IWorkQueueUidEntityBroker workQueueUidBroker = context.GetBroker <IWorkQueueUidEntityBroker>(); IStudyIntegrityQueueUidEntityBroker duplicateUidBroke = context.GetBroker <IStudyIntegrityQueueUidEntityBroker>(); foreach (StudyIntegrityQueueUid uid in uids) { WorkQueueUidUpdateColumns uidColumns = new WorkQueueUidUpdateColumns { Duplicate = true, Extension = ServerPlatform.DuplicateFileExtension, SeriesInstanceUid = uid.SeriesInstanceUid, SopInstanceUid = uid.SopInstanceUid, RelativePath = uid.RelativePath, WorkQueueKey = processDuplicateWorkQueueEntry.GetKey() }; workQueueUidBroker.Insert(uidColumns); duplicateUidBroke.Delete(uid.GetKey()); } IDuplicateSopEntryEntityBroker duplicateEntryBroker = context.GetBroker <IDuplicateSopEntryEntityBroker>(); duplicateEntryBroker.Delete(entry.GetKey()); context.Commit(); } }