Skip to content

Commit 50f1ed2

Browse files
committed
Fixed comments
1 parent 5c546b8 commit 50f1ed2

File tree

9 files changed

+56
-29
lines changed

9 files changed

+56
-29
lines changed

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" />
7777
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
7878
<PackageVersion Include="System.Text.Json" Version="6.0.10" />
79+
<PackageVersion Include="System.Collections.Immutable" Version="6.0.1" />
7980
</ItemGroup>
8081

8182
</Project>

src/Abstractions/Abstractions.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
1313
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
1414
<PackageReference Include="System.Text.Json" />
15+
<PackageReference Include="System.Collections.Immutable"/>
1516
</ItemGroup>
1617

1718
<ItemGroup>

src/Abstractions/TaskOptions.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,32 @@ public SubOrchestrationOptions(TaskOptions options, string? instanceId = null)
103103
public record StartOrchestrationOptions(string? InstanceId = null, DateTimeOffset? StartAt = null)
104104
{
105105
/// <summary>
106-
/// Gets or sets the tags to associate with the orchestration instance. Tags are key-value pairs that can be used.
106+
/// Gets the tags to associate with the orchestration instance. Tags are key-value pairs that can be used.
107107
/// </summary>
108-
public IDictionary<string, string>? Tags { get; init; } = new Dictionary<string, string>();
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+
/// <returns>A new <see cref="StartOrchestrationOptions"/> with the combined tags.</returns>
115+
public StartOrchestrationOptions AddTags(IEnumerable<KeyValuePair<string, string>> tags)
116+
{
117+
var currentTags = this.Tags as System.Collections.Immutable.ImmutableDictionary<string, string>
118+
?? System.Collections.Immutable.ImmutableDictionary.Create<string, string>();
119+
return this with { Tags = currentTags.AddRange(tags) };
120+
}
121+
122+
/// <summary>
123+
/// Returns a new <see cref="StartOrchestrationOptions"/> with the provided tag added to the existing tags.
124+
/// </summary>
125+
/// <param name="key">The tag key.</param>
126+
/// <param name="value">The tag value.</param>
127+
/// <returns>A new <see cref="StartOrchestrationOptions"/> with the combined tags.</returns>
128+
public StartOrchestrationOptions AddTag(string key, string value)
129+
{
130+
var currentTags = this.Tags as System.Collections.Immutable.ImmutableDictionary<string, string>
131+
?? System.Collections.Immutable.ImmutableDictionary.Create<string, string>();
132+
return this with { Tags = currentTags.Add(key, value) };
133+
}
109134
}

src/Client/Core/OrchestrationMetadata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public OrchestrationMetadata(string name, string instanceId)
8282
/// <summary>
8383
/// Gets the tags associated with the orchestration instance.
8484
/// </summary>
85-
public IReadOnlyDictionary<string, string> Tags { get; init; } = new Dictionary<string, string>();
85+
public IDictionary<string, string> Tags { get; } = new Dictionary<string, string>();
8686

8787
/// <summary>
8888
/// Gets the failure details, if any, for the orchestration instance.

src/Client/Grpc/GrpcDurableTaskClient.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ async Task<PurgeResult> PurgeInstancesCoreAsync(
457457

458458
OrchestrationMetadata CreateMetadata(P.OrchestrationState state, bool includeInputsAndOutputs)
459459
{
460-
return new(state.Name, state.InstanceId)
460+
var metadata = new OrchestrationMetadata(state.Name, state.InstanceId)
461461
{
462462
CreatedAt = state.CreatedTimestamp.ToDateTimeOffset(),
463463
LastUpdatedAt = state.LastUpdatedTimestamp.ToDateTimeOffset(),
@@ -467,7 +467,13 @@ OrchestrationMetadata CreateMetadata(P.OrchestrationState state, bool includeInp
467467
SerializedCustomStatus = state.CustomStatus,
468468
FailureDetails = state.FailureDetails.ToTaskFailureDetails(),
469469
DataConverter = includeInputsAndOutputs ? this.DataConverter : null,
470-
Tags = state.Tags.ToDictionary(x => x.Key, x => x.Value),
471470
};
471+
472+
foreach (var tag in state.Tags)
473+
{
474+
metadata.Tags.Add(tag.Key, tag.Value);
475+
}
476+
477+
return metadata;
472478
}
473479
}

src/Client/OrchestrationServiceClientShim/ShimDurableTaskClient.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System.Diagnostics.CodeAnalysis;
55
using DurableTask.Core;
6-
using DurableTask.Core.Entities;
76
using DurableTask.Core.History;
87
using DurableTask.Core.Query;
98
using Microsoft.DurableTask.Client.Entities;
@@ -176,7 +175,7 @@ public override async Task<string> ScheduleNewOrchestrationInstanceAsync(
176175
Version = orchestratorName.Version,
177176
OrchestrationInstance = instance,
178177
ScheduledStartTime = options?.StartAt?.UtcDateTime,
179-
Tags = options?.Tags,
178+
Tags = options?.Tags != null ? options.Tags.ToDictionary(kvp => kvp.Key, kvp => kvp.Value) : null,
180179
},
181180
};
182181

test/Client/OrchestrationServiceClientShim.Tests/ShimDurableTaskClientTests.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,14 +316,19 @@ 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-
}
324319
};
320+
options.AddTag("key", "value");
321+
options.AddTag("key2", "value2");
325322

326323
await this.RunScheduleNewOrchestrationInstanceAsync("test", "input", options);
324+
325+
OrchestrationMetadata metadata = await this.client.WaitForInstanceStartAsync(
326+
options.InstanceId, false, default);
327+
328+
this.orchestrationClient.Verify(
329+
m => m.CreateTaskOrchestrationAsync(MatchStartExecutionMessage("test", "input", options)),
330+
Times.Once());
331+
metadata.Tags.Should().HaveCount(2);
327332
}
328333

329334

test/Grpc.IntegrationTests/IntegrationTestBase.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public IntegrationTestBase(ITestOutputHelper output, GrpcSidecarFixture sidecarF
4040
void IDisposable.Dispose()
4141
{
4242
this.testTimeoutSource.Dispose();
43-
this.sidecarFixture.Dispose();
4443
GC.SuppressFinalize(this);
4544
}
4645

test/Grpc.IntegrationTests/OrchestrationPatterns.cs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.DurableTask.Tests.Logging;
88
using Microsoft.DurableTask.Worker;
99
using Microsoft.Extensions.DependencyInjection;
10+
using Microsoft.Extensions.Options;
1011
using Xunit.Abstractions;
1112

1213
namespace Microsoft.DurableTask.Grpc.Tests;
@@ -44,14 +45,11 @@ public async Task ScheduleOrchesrationWithTags()
4445
b.AddTasks(tasks => tasks.AddOrchestratorFunc(orchestratorName, ctx => Task.FromResult<object?>(null)));
4546
});
4647

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

5654
OrchestrationMetadata metadata = await server.Client.WaitForInstanceCompletionAsync(
5755
instanceId, this.TimeoutToken);
@@ -202,14 +200,7 @@ public async Task SingleActivity()
202200
.AddActivityFunc<string, string>(sayHelloActivityName, (ctx, name) => $"Hello, {name}!"));
203201
});
204202

205-
string instanceId = await server.Client.ScheduleNewOrchestrationInstanceAsync(orchestratorName, input: "World", new StartOrchestrationOptions
206-
{
207-
Tags = new Dictionary<string, string>()
208-
{
209-
{ "tag1", "value1" },
210-
{ "tag2", "value2" }
211-
}
212-
});
203+
string instanceId = await server.Client.ScheduleNewOrchestrationInstanceAsync(orchestratorName, input: "World");
213204
OrchestrationMetadata metadata = await server.Client.WaitForInstanceCompletionAsync(
214205
instanceId, getInputsAndOutputs: true, this.TimeoutToken);
215206
Assert.NotNull(metadata);

0 commit comments

Comments
 (0)