-
Notifications
You must be signed in to change notification settings - Fork 52
Add support for multi instance query #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
acab5ef
Add AsyncPageable<T> abstractions
jviau aa171ac
Add GetInstances method to DurableTaskClient
jviau c68d6f3
Add newlines at end of files
jviau d0997ae
Make Pageable helpers internal
jviau 26e1b03
Page.cs -> Page{T}.cs
jviau 948bf87
Clarify code reference comments, add return comment
jviau b9407f2
Add tests, msbuild updates, remove ConfigureAwait
jviau 724a8c1
Remove IReadOnlyList<T> from Page<T> to allow for serialization
jviau e84a7ea
Fix end of file new lines
jviau ab0fb46
Rename strong name key property
jviau ad38f69
Add instance query end-to-end tests
jviau 9fe5363
Add FirstAsync example to tests
jviau e394350
Fix test failures
jviau 5120296
Fix test failures
jviau 25c0f42
Address PR comments
jviau 891e702
Merge branch 'main' into multi-instance-query
jviau a5f758e
Fix unit test conditions
jviau 3c0d737
Merge branch 'multi-instance-query' of https://github.com/jviau/durab…
jviau 3e3d18a
Change comment location
jviau ef38441
Fix comment
jviau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <Project> | ||
|
|
||
| <!-- Common build settings --> | ||
| <PropertyGroup> | ||
| <LangVersion>10.0</LangVersion> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| </PropertyGroup> | ||
|
|
||
| <!-- Signing --> | ||
| <PropertyGroup> | ||
| <SignAssembly>true</SignAssembly> | ||
| <AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)eng/key.snk</AssemblyOriginatorKeyFile> | ||
| <StrongNamePublicKey>00240000048000009400000006020000002400005253413100040000010001000505410141442095e0b0466df68ac32d158abdf0bd9cf26407d7a9d20b93656530556f23979f20b067628b9baee75fc6bba5c349519585a2852c1843bc61d74c4cbf9d80429cbdcbf609ea70fd62061eb65f40a6c9d505dd71cb119ef51f589a014d3b56159abbc38825fafbd119b6e97ebd9a5f3862a5c06220c680a6ac9eec</StrongNamePublicKey> | ||
| </PropertyGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <Project> | ||
| <Import Project="$(MSBuildThisFileDirectory)eng/InternalsVisibleTo.targets" /> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| <!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. --> | ||
| <Project> | ||
|
|
||
| <PropertyGroup> | ||
| <GeneratedInternalsVisibleToFile>$(IntermediateOutputPath)$(MSBuildProjectName).InternalsVisibleTo$(DefaultLanguageSourceExtension)</GeneratedInternalsVisibleToFile> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemDefinitionGroup> | ||
| <InternalsVisibleTo> | ||
| <Visible>false</Visible> | ||
| </InternalsVisibleTo> | ||
| </ItemDefinitionGroup> | ||
|
|
||
| <Target Name="PrepareGenerateInternalsVisibleToFile" Condition="'@(InternalsVisibleTo)' != ''"> | ||
|
|
||
| <ItemGroup> | ||
| <_InternalsVisibleToAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute"> | ||
| <_Parameter1 Condition="'%(InternalsVisibleTo.Key)' != ''">%(InternalsVisibleTo.Identity), PublicKey=%(InternalsVisibleTo.Key)</_Parameter1> | ||
| <_Parameter1 Condition="'%(InternalsVisibleTo.Key)' == '' and '$(PublicKey)' != ''">%(InternalsVisibleTo.Identity), PublicKey=$(PublicKey)</_Parameter1> | ||
| <_Parameter1 Condition="'%(InternalsVisibleTo.Key)' == '' and '$(PublicKey)' == ''">%(InternalsVisibleTo.Identity)</_Parameter1> | ||
| </_InternalsVisibleToAttribute> | ||
| </ItemGroup> | ||
|
|
||
| </Target> | ||
|
|
||
| <!-- | ||
| Dependency on PrepareForBuild is necessary so that we don't accidentally get ordered before it. | ||
| We rely on PrepareForBuild to create the IntermediateOutputDirectory if it doesn't exist. | ||
| --> | ||
| <Target Name="GenerateInternalsVisibleToFile" | ||
| Inputs="$(MSBuildThisFileFullPath);$(MSBuildProjectFile)" | ||
| Outputs="$(GeneratedInternalsVisibleToFile)" | ||
| DependsOnTargets="PrepareGenerateInternalsVisibleToFile;PrepareForBuild" | ||
| Condition="'@(InternalsVisibleTo)' != ''" | ||
| BeforeTargets="CoreCompile"> | ||
|
|
||
| <WriteCodeFragment AssemblyAttributes="@(_InternalsVisibleToAttribute)" Language="$(Language)" OutputFile="$(GeneratedInternalsVisibleToFile)"> | ||
| <Output TaskParameter="OutputFile" ItemName="CompileBefore" Condition="'$(Language)' == 'F#'" /> | ||
| <Output TaskParameter="OutputFile" ItemName="Compile" Condition="'$(Language)' != 'F#'" /> | ||
| <Output TaskParameter="OutputFile" ItemName="FileWrites" /> | ||
| </WriteCodeFragment> | ||
|
|
||
| </Target> | ||
|
|
||
| </Project> |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Microsoft.DurableTask; | ||
|
|
||
| /// <summary> | ||
| /// A collection of values that may take multiple service requests to iterate over. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type of the value.</typeparam> | ||
| public abstract class AsyncPageable<T> : IAsyncEnumerable<T> | ||
| where T : notnull | ||
| { | ||
| // This code was adapted from Azure SDK AsyncPageable. | ||
| // https://github.com/Azure/azure-sdk-for-net/blob/e811f016a3655e4b29a23c71f84d59f34fe01233/sdk/core/Azure.Core/src/AsyncPageable.cs | ||
|
|
||
| /// <summary> | ||
| /// Enumerate the values a <see cref="Page{T}"/> at a time. | ||
| /// </summary> | ||
| /// <param name="continuationToken"> | ||
| /// A continuation token indicating where to resume paging or null to begin paging from the | ||
| /// beginning. | ||
| /// </param> | ||
| /// <param name="pageSizeHint"> | ||
| /// The number of items per <see cref="Page{T}"/> that should be requested | ||
| /// (from service operations that support it). It's not guaranteed that the value will be | ||
| /// respected. | ||
| /// </param> | ||
| /// <returns>An async enumerable of pages.</returns> | ||
| public abstract IAsyncEnumerable<Page<T>> AsPages( | ||
| string? continuationToken = default, int? pageSizeHint = default); | ||
|
|
||
| /// <inheritdoc/> | ||
| public async IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default) | ||
| { | ||
| // TODO: ConfigureAwait(false)? This may cause issues when used in an orchestration. | ||
| await foreach (Page<T> page in this.AsPages().WithCancellation(cancellationToken)) | ||
| { | ||
| foreach (T value in page.Values) | ||
| { | ||
| yield return value; | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Microsoft.DurableTask; | ||
|
|
||
| /// <summary> | ||
| /// A filter for querying orchestration instances. | ||
| /// </summary> | ||
| /// <param name="CreatedFrom">Creation date of instances to query from.</param> | ||
| /// <param name="CreatedTo">Creation date of instances to query to.</param> | ||
| /// <param name="Statuses">Runtime statuses of instances to query.</param> | ||
| /// <param name="TaskHubNames">Names of task hubs to query across.</param> | ||
| /// <param name="InstanceIdPrefix">Prefix of instance IDs to include.</param> | ||
| /// <param name="PageSize">Max item count to include per page.</param> | ||
| /// <param name="FetchInputsAndOutputs">Whether to include instance inputs or outputs in the query results.</param> | ||
| /// <param name="ContinuationToken">The continuation token to continue a paged query.</param> | ||
| public record OrchestrationQuery( | ||
| DateTimeOffset? CreatedFrom = null, | ||
| DateTimeOffset? CreatedTo = null, | ||
| IEnumerable<OrchestrationRuntimeStatus>? Statuses = null, | ||
| IEnumerable<string>? TaskHubNames = null, | ||
| string? InstanceIdPrefix = null, | ||
| int PageSize = OrchestrationQuery.DefaultPageSize, | ||
| bool FetchInputsAndOutputs = false, | ||
| string? ContinuationToken = null) | ||
| { | ||
| /// <summary> | ||
| /// The default page size when not supplied. | ||
| /// </summary> | ||
| public const int DefaultPageSize = 100; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Runtime.CompilerServices; | ||
|
|
||
| namespace Microsoft.DurableTask; | ||
|
|
||
| /// <summary> | ||
| /// Pageable helpers. | ||
| /// </summary> | ||
| static class Pageable | ||
| { | ||
| // This code was adapted from Azure SDK PageResponseEnumerator. | ||
| // https://github.com/Azure/azure-sdk-for-net/blob/e811f016a3655e4b29a23c71f84d59f34fe01233/sdk/core/Azure.Core/src/Shared/PageResponseEnumerator.cs | ||
| // TODO: Add Pageable<T> (non-async) when/if it becomes relevant. | ||
|
|
||
| /// <summary> | ||
| /// Creates an async pageable from a callback function <paramref name="pageFunc" />. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type of the value.</typeparam> | ||
| /// <param name="pageFunc">The callback to fetch additional pages.</param> | ||
| /// <returns>An async pageable.</returns> | ||
| public static AsyncPageable<T> Create<T>(Func<string?, CancellationToken, Task<Page<T>>> pageFunc) | ||
| where T : notnull | ||
| { | ||
| if (pageFunc is null) | ||
| { | ||
| throw new ArgumentNullException(nameof(pageFunc)); | ||
| } | ||
|
|
||
| return Create((continuation, size, cancellation) => pageFunc(continuation, cancellation)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates an async pageable from a callback function <paramref name="pageFunc" />. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type of the value.</typeparam> | ||
| /// <param name="pageFunc">The callback to fetch additional pages.</param> | ||
| /// <returns>An async pageable.</returns> | ||
| public static AsyncPageable<T> Create<T>(Func<string?, int?, CancellationToken, Task<Page<T>>> pageFunc) | ||
| where T : notnull | ||
| { | ||
| if (pageFunc is null) | ||
| { | ||
| throw new ArgumentNullException(nameof(pageFunc)); | ||
| } | ||
|
|
||
| return new FuncAsyncPageable<T>(pageFunc); | ||
| } | ||
|
|
||
| class FuncAsyncPageable<T> : AsyncPageable<T> | ||
| where T : notnull | ||
| { | ||
| readonly Func<string?, int?, CancellationToken, Task<Page<T>>> pageFunc; | ||
|
|
||
| public FuncAsyncPageable(Func<string?, int?, CancellationToken, Task<Page<T>>> pageFunc) | ||
| { | ||
| this.pageFunc = pageFunc; | ||
| } | ||
|
|
||
| public override IAsyncEnumerable<Page<T>> AsPages( | ||
| string? continuationToken = default, int? pageSizeHint = default) | ||
| => this.AsPagesCore(continuationToken, pageSizeHint); | ||
|
|
||
| async IAsyncEnumerable<Page<T>> AsPagesCore( | ||
| string? continuationToken = default, | ||
| int? pageSizeHint = default, | ||
| [EnumeratorCancellation] CancellationToken cancellation = default) | ||
| { | ||
| do | ||
| { | ||
| // TODO: Do we need to support customizing ConfigureAwait(bool) here? | ||
| // ConfigureAwait(false) makes this unusable in orchestrations. | ||
| Page<T> page = await this.pageFunc(continuationToken, pageSizeHint, cancellation); | ||
| yield return page; | ||
| continuationToken = page.ContinuationToken; | ||
| } | ||
| while (continuationToken is not null); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.