/// <inheritdoc/>
        public async Task <Guid> StartReindexingInstancesAsync(IReadOnlyCollection <int> tagKeys, CancellationToken cancellationToken = default)
        {
            EnsureArg.IsNotNull(tagKeys, nameof(tagKeys));
            EnsureArg.HasItems(tagKeys, nameof(tagKeys));

            // Start the re-indexing orchestration
            Guid instanceGuid = _guidFactory.Create();

            // TODO: Pass token when supported
            string instanceId = await _durableClient.StartNewAsync(
                FunctionNames.ReindexInstances,
                OperationId.ToString(instanceGuid),
                new ReindexInput { QueryTagKeys = tagKeys });

            _logger.LogInformation("Successfully started new orchestration instance with ID '{InstanceId}'.", instanceId);

            // Associate the tags to the operation and confirm their processing
            IReadOnlyList <ExtendedQueryTagStoreEntry> confirmedTags = await _extendedQueryTagStore.AssignReindexingOperationAsync(
                tagKeys,
                instanceGuid,
                returnIfCompleted : true,
                cancellationToken : cancellationToken);

            return(confirmedTags.Count > 0 ? instanceGuid : throw new ExtendedQueryTagsAlreadyExistsException());
        }
Example #2
0
        public async Task GivenValidExtendedQueryTags_WhenGettingExtendedQueryTagsByKey_ThenOnlyPresentTagsAreReturned()
        {
            Guid     id   = Guid.NewGuid();
            DicomTag tag1 = DicomTag.DeviceSerialNumber;
            DicomTag tag2 = new DicomTag(0x0405, 0x1001, "PrivateCreator1");
            AddExtendedQueryTagEntry expected1 = tag1.BuildAddExtendedQueryTagEntry();
            AddExtendedQueryTagEntry expected2 = tag2.BuildAddExtendedQueryTagEntry(vr: DicomVRCode.CS);
            int key1 = (await AddExtendedQueryTagsAsync(new AddExtendedQueryTagEntry[] { expected1 }, ready: false)).Single();
            int key2 = (await AddExtendedQueryTagsAsync(new AddExtendedQueryTagEntry[] { expected2 }, ready: true)).Single();
            await _extendedQueryTagStore.AssignReindexingOperationAsync(new List <int> {
                key1
            }, id);

            // Fetch the newly added keys (and pass 1 more key we know doesn't have a corresponding entry)
            IReadOnlyList <ExtendedQueryTagStoreJoinEntry> actual = await _extendedQueryTagStore.GetExtendedQueryTagsAsync(new int[] { key1, key2, key2 + 1 });

            Assert.Equal(2, actual.Count);
            AssertTag(key1, expected1, actual[0], ExtendedQueryTagStatus.Adding, operationId: id);
            AssertTag(key2, expected2, actual[1], ExtendedQueryTagStatus.Ready);
        }