Skip to content

Commit 2b44693

Browse files
committed
Address comments
1 parent ec04405 commit 2b44693

File tree

5 files changed

+18
-43
lines changed

5 files changed

+18
-43
lines changed

src/Abstractions/TaskOptions.cs

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4+
using System.Collections.Immutable;
5+
46
namespace Microsoft.DurableTask;
57

68
/// <summary>
@@ -105,39 +107,5 @@ public record StartOrchestrationOptions(string? InstanceId = null, DateTimeOffse
105107
/// <summary>
106108
/// Gets the tags to associate with the orchestration instance. Tags are key-value pairs that can be used.
107109
/// </summary>
108-
public IEnumerable<KeyValuePair<string, string>> Tags { get; private set; } = System.Collections.Immutable.ImmutableDictionary.Create<string, string>();
109-
110-
/// <summary>
111-
/// Returns a new <see cref="StartOrchestrationOptions"/> with the provided tags added to the existing tags.
112-
/// </summary>
113-
/// <param name="tags">The tags to add.</param>
114-
public void AddTags(IEnumerable<KeyValuePair<string, string>> tags)
115-
{
116-
var currentTags = this.Tags as System.Collections.Immutable.ImmutableDictionary<string, string>
117-
?? System.Collections.Immutable.ImmutableDictionary.Create<string, string>();
118-
this.Tags = currentTags.AddRange(tags);
119-
}
120-
121-
/// <summary>
122-
/// Returns a new <see cref="StartOrchestrationOptions"/> with the provided tag added to the existing tags.
123-
/// </summary>
124-
/// <param name="key">The tag key.</param>
125-
/// <param name="value">The tag value.</param>
126-
public void AddTag(string key, string value)
127-
{
128-
if (string.IsNullOrEmpty(key))
129-
{
130-
throw new ArgumentException("Tag key cannot be null or empty.", nameof(key));
131-
}
132-
133-
if (string.IsNullOrEmpty(value))
134-
{
135-
throw new ArgumentException("Tag value cannot be null or empty.", nameof(value));
136-
}
137-
138-
var currentTags = this.Tags as System.Collections.Immutable.ImmutableDictionary<string, string>
139-
?? System.Collections.Immutable.ImmutableDictionary.Create<string, string>();
140-
141-
this.Tags = currentTags.Add(key, value);
142-
}
110+
public IReadOnlyDictionary<string, string> Tags { get; init; } = ImmutableDictionary.Create<string, string>();
143111
}

src/Client/Core/OrchestrationMetadata.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4+
using System.Collections.Immutable;
45
using System.Diagnostics.CodeAnalysis;
56
using System.Text;
67

@@ -82,7 +83,7 @@ public OrchestrationMetadata(string name, string instanceId)
8283
/// <summary>
8384
/// Gets the tags associated with the orchestration instance.
8485
/// </summary>
85-
public IReadOnlyDictionary<string, string> Tags { get; init; }
86+
public IReadOnlyDictionary<string, string> Tags { get; init; } = ImmutableDictionary.Create<string, string>();
8687

8788
/// <summary>
8889
/// Gets the failure details, if any, for the orchestration instance.

src/Worker/Grpc/GrpcDurableTaskWorker.Processor.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ async ValueTask<OrchestrationRuntimeState> BuildRuntimeStateAsync(
112112
ProtoUtils.EntityConversionState? entityConversionState,
113113
CancellationToken cancellation)
114114
{
115-
116115
Func<P.HistoryEvent, HistoryEvent> converter = entityConversionState is null
117116
? ProtoUtils.ConvertHistoryEvent
118117
: entityConversionState.ConvertFromProto;

test/Client/OrchestrationServiceClientShim.Tests/ShimDurableTaskClientTests.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,12 @@ public async Task ScheduleNewOrchestrationInstance_IdProvided_TagsProvided()
316316
StartOrchestrationOptions options = new()
317317
{
318318
InstanceId = "test-id",
319+
Tags = new Dictionary<string, string>
320+
{
321+
{ "tag1", "value1" },
322+
{ "tag2", "value2" }
323+
}
319324
};
320-
options.AddTag("key", "value");
321-
options.AddTag("key2", "value2");
322-
323325
await this.RunScheduleNewOrchestrationInstanceAsync("test", "input", options);
324326
}
325327

test/Grpc.IntegrationTests/OrchestrationPatterns.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,14 @@ public async Task ScheduleOrchesrationWithTags()
4646
});
4747

4848
// Schedule a new orchestration instance with tags
49-
var options = new StartOrchestrationOptions();
50-
options.AddTag("tag1", "value1");
51-
options.AddTag("tag2", "value2");
49+
StartOrchestrationOptions options = new()
50+
{
51+
Tags = new Dictionary<string, string>
52+
{
53+
{ "tag1", "value1" },
54+
{ "tag2", "value2" }
55+
}
56+
};
5257
string instanceId = await server.Client.ScheduleNewOrchestrationInstanceAsync(orchestratorName, options);
5358

5459
OrchestrationMetadata metadata = await server.Client.WaitForInstanceCompletionAsync(

0 commit comments

Comments
 (0)