-
Notifications
You must be signed in to change notification settings - Fork 54
Introduce WorkItemFilters into worker flow #616
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
10 commits
Select commit
Hold shift + click to select a range
8b43e7f
Introduce WorkItemFilters into worker flow
halspang 540aaf3
Add tests, update filter construction
halspang 704b03f
Update comments, handle named builder
halspang 9445a6d
Use Version for registration, add defaults to struct
halspang 9d25bc0
Make filters on by default
halspang a2ab20d
Update protos
halspang 5a66287
Better handle null filters + testing
halspang 4f45291
Fix comment formatting
halspang 1c504fc
Fix default constructor issue
halspang 481eddc
Update default version handling
halspang 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
Some comments aren't visible on the classic Files Changed page.
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
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 |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| # The following files were downloaded from branch main at 2026-01-13 00:01:21 UTC | ||
| https://raw.githubusercontent.com/microsoft/durabletask-protobuf/026329c53fe6363985655857b9ca848ec7238bd2/protos/orchestrator_service.proto | ||
| # The following files were downloaded from branch main at 2026-02-24 00:01:28 UTC | ||
| https://raw.githubusercontent.com/microsoft/durabletask-protobuf/1caadbd7ecfdf5f2309acbeac28a3e36d16aa156/protos/orchestrator_service.proto |
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,137 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Microsoft.DurableTask.Worker; | ||
|
|
||
| /// <summary> | ||
| /// A class that represents work item filters for a Durable Task Worker. These filters are passed to the backend | ||
| /// and only work items matching the filters will be processed by the worker. If no filters are provided, | ||
| /// the worker will process all work items. By default, these are auto-generated from the registered orchestrations, | ||
| /// activities, and entities in the <see cref="DurableTaskRegistry"/>. To opt-out of filters, provide a <c>null</c> | ||
| /// value to the <see cref="DurableTaskWorkerBuilderExtensions.UseWorkItemFilters"/> method when configuring the worker. | ||
| /// </summary> | ||
| public class DurableTaskWorkerWorkItemFilters | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the orchestration filters. | ||
| /// </summary> | ||
| public IReadOnlyList<OrchestrationFilter> Orchestrations { get; set; } = []; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the activity filters. | ||
| /// </summary> | ||
| public IReadOnlyList<ActivityFilter> Activities { get; set; } = []; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the entity filters. | ||
| /// </summary> | ||
| public IReadOnlyList<EntityFilter> Entities { get; set; } = []; | ||
|
|
||
| /// <summary> | ||
| /// Creates a new instance of the <see cref="DurableTaskWorkerWorkItemFilters"/> class. | ||
| /// </summary> | ||
| /// <param name="registry"><see cref="DurableTaskRegistry"/> to construct the filter from.</param> | ||
| /// <param name="workerOptions"><see cref="DurableTaskWorkerOptions"/> that optionally provides versioning information.</param> | ||
| /// <returns>A new instance of <see cref="DurableTaskWorkerWorkItemFilters"/> constructed from the provided registry.</returns> | ||
| internal static DurableTaskWorkerWorkItemFilters FromDurableTaskRegistry(DurableTaskRegistry registry, DurableTaskWorkerOptions? workerOptions) | ||
| { | ||
| // TODO: Support multiple versions per orchestration/activity. | ||
| // For now, fetch the version based on the versioning match strategy if defined. If undefined, default to null (all versions match). | ||
| IReadOnlyList<string> versions = []; | ||
| if (workerOptions?.Versioning?.MatchStrategy == DurableTaskWorkerOptions.VersionMatchStrategy.Strict) | ||
| { | ||
| versions = [workerOptions.Versioning.Version]; | ||
| } | ||
|
|
||
| return new DurableTaskWorkerWorkItemFilters | ||
| { | ||
| Orchestrations = registry.Orchestrators.Select(orchestration => new OrchestrationFilter | ||
| { | ||
| Name = orchestration.Key, | ||
| Versions = versions, | ||
| }).ToList(), | ||
| Activities = registry.Activities.Select(activity => new ActivityFilter | ||
| { | ||
| Name = activity.Key, | ||
| Versions = versions, | ||
| }).ToList(), | ||
| Entities = registry.Entities.Select(entity => new EntityFilter | ||
| { | ||
| // Entity names are normalized to lowercase in the backend. | ||
| Name = entity.Key.ToString(), | ||
| }).ToList(), | ||
| }; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Specifies an orchestration filter. | ||
| /// </summary> | ||
| /// <param name="name">The name of the orchestration.</param> | ||
| /// <param name="versions">The optional versions of the orchestration.</param> | ||
| public readonly struct OrchestrationFilter(string name, IReadOnlyList<string>? versions) | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="OrchestrationFilter"/> struct with default values. | ||
| /// </summary> | ||
| public OrchestrationFilter() | ||
| : this(string.Empty, []) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets or initializes the name of the orchestration to filter. | ||
| /// </summary> | ||
| public string Name { get; init; } = name; | ||
|
|
||
| /// <summary> | ||
| /// Gets or initializes the versions of the orchestration to filter. | ||
| /// </summary> | ||
| public IReadOnlyList<string> Versions { get; init; } = versions ?? []; | ||
halspang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /// <summary> | ||
| /// Specifies an activity filter. | ||
| /// </summary> | ||
| /// <param name="name">The name of the activity.</param> | ||
| /// <param name="versions">The optional versions of the activity.</param> | ||
| public readonly struct ActivityFilter(string name, IReadOnlyList<string>? versions) | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="ActivityFilter"/> struct with default values. | ||
| /// </summary> | ||
| public ActivityFilter() | ||
| : this(string.Empty, []) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets or initializes the name of the activity to filter. | ||
| /// </summary> | ||
| public string Name { get; init; } = name; | ||
|
|
||
| /// <summary> | ||
| /// Gets or initializes the versions of the activity to filter. | ||
| /// </summary> | ||
| public IReadOnlyList<string> Versions { get; init; } = versions ?? []; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Specifies an entity filter. | ||
| /// </summary> | ||
| /// <param name="name">The name of the entity.</param> | ||
| public readonly struct EntityFilter(string name) | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="EntityFilter"/> struct with default values. | ||
| /// </summary> | ||
| public EntityFilter() | ||
| : this(string.Empty) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets or initializes the name of the entity to filter. | ||
| /// </summary> | ||
| public string Name { get; init; } = name; | ||
| } | ||
| } | ||
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
53 changes: 53 additions & 0 deletions
53
src/Worker/Grpc/Internal/DurableTaskWorkerWorkItemFiltersExtension.cs
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,53 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using P = Microsoft.DurableTask.Protobuf; | ||
|
|
||
| namespace Microsoft.DurableTask.Worker.Grpc.Internal; | ||
|
|
||
| /// <summary> | ||
| /// Extension for <see cref="DurableTaskWorkerWorkItemFilters"/> to convert to gRPC types. | ||
| /// </summary> | ||
| public static class DurableTaskWorkerWorkItemFiltersExtension | ||
| { | ||
| /// <summary> | ||
| /// Converts a <see cref="DurableTaskWorkerWorkItemFilters"/> to a gRPC <see cref="P.WorkItemFilters"/>. | ||
| /// </summary> | ||
| /// <param name="workItemFilter">The <see cref="DurableTaskWorkerWorkItemFilters"/> to convert.</param> | ||
| /// <returns>A gRPC <see cref="P.WorkItemFilters"/>.</returns> | ||
| public static P.WorkItemFilters ToGrpcWorkItemFilters(this DurableTaskWorkerWorkItemFilters workItemFilter) | ||
| { | ||
halspang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Check.NotNull(workItemFilter); | ||
| var grpcWorkItemFilters = new P.WorkItemFilters(); | ||
| foreach (var orchestrationFilter in workItemFilter.Orchestrations) | ||
| { | ||
| var grpcOrchestrationFilter = new P.OrchestrationFilter | ||
| { | ||
| Name = orchestrationFilter.Name, | ||
| }; | ||
| grpcOrchestrationFilter.Versions.AddRange(orchestrationFilter.Versions); | ||
halspang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| grpcWorkItemFilters.Orchestrations.Add(grpcOrchestrationFilter); | ||
| } | ||
|
|
||
| foreach (var activityFilter in workItemFilter.Activities) | ||
| { | ||
| var grpcActivityFilter = new P.ActivityFilter | ||
| { | ||
| Name = activityFilter.Name, | ||
| }; | ||
| grpcActivityFilter.Versions.AddRange(activityFilter.Versions); | ||
| grpcWorkItemFilters.Activities.Add(grpcActivityFilter); | ||
| } | ||
|
|
||
| foreach (var entityFilter in workItemFilter.Entities) | ||
| { | ||
| var grpcEntityFilter = new P.EntityFilter | ||
| { | ||
| Name = entityFilter.Name, | ||
| }; | ||
| grpcWorkItemFilters.Entities.Add(grpcEntityFilter); | ||
| } | ||
halspang marked this conversation as resolved.
Show resolved
Hide resolved
halspang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return grpcWorkItemFilters; | ||
| } | ||
| } | ||
Oops, something went wrong.
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.