Skip to content

Commit d11758c

Browse files
author
Sophia Tevosyan
committed
addressing PR comments
1 parent 44d654f commit d11758c

File tree

7 files changed

+70
-93
lines changed

7 files changed

+70
-93
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33

44
using DurableTask.Core;
55

6-
namespace Microsoft.DurableTask.Worker.Grpc;
6+
namespace Microsoft.DurableTask.Worker;
77

88
/// <summary>
99
/// Represents the state of an extended session for an orchestration.
1010
/// </summary>
11-
class ExtendedSessionState
11+
public class ExtendedSessionState
1212
{
1313
/// <summary>
1414
/// Initializes a new instance of the <see cref="ExtendedSessionState"/> class.
1515
/// </summary>
1616
/// <param name="state">The orchestration's runtime state.</param>
1717
/// <param name="taskOrchestration">The TaskOrchestration implementation of the orchestration.</param>
1818
/// <param name="orchestrationExecutor">The TaskOrchestrationExecutor for the orchestration.</param>
19-
internal ExtendedSessionState(OrchestrationRuntimeState state, TaskOrchestration taskOrchestration, TaskOrchestrationExecutor orchestrationExecutor)
19+
public ExtendedSessionState(OrchestrationRuntimeState state, TaskOrchestration taskOrchestration, TaskOrchestrationExecutor orchestrationExecutor)
2020
{
2121
this.RuntimeState = state;
2222
this.TaskOrchestration = taskOrchestration;
@@ -26,15 +26,15 @@ internal ExtendedSessionState(OrchestrationRuntimeState state, TaskOrchestration
2626
/// <summary>
2727
/// Gets or sets the saved runtime state of the orchestration.
2828
/// </summary>
29-
internal OrchestrationRuntimeState RuntimeState { get; set; }
29+
public OrchestrationRuntimeState RuntimeState { get; set; }
3030

3131
/// <summary>
3232
/// Gets or sets the saved TaskOrchestration implementation of the orchestration.
3333
/// </summary>
34-
internal TaskOrchestration TaskOrchestration { get; set; }
34+
public TaskOrchestration TaskOrchestration { get; set; }
3535

3636
/// <summary>
3737
/// Gets or sets the saved TaskOrchestrationExecutor.
3838
/// </summary>
39-
internal TaskOrchestrationExecutor OrchestrationExecutor { get; set; }
39+
public TaskOrchestrationExecutor OrchestrationExecutor { get; set; }
4040
}
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using Microsoft.Extensions.Caching.Memory;
55

6-
namespace Microsoft.DurableTask.Worker.Grpc;
6+
namespace Microsoft.DurableTask.Worker;
77

88
/// <summary>
99
/// A cache for extended sessions that wraps a <see cref="MemoryCache"/> instance.
@@ -13,6 +13,12 @@ public class ExtendedSessionsCache : IDisposable
1313
{
1414
MemoryCache? extendedSessions;
1515

16+
/// <summary>
17+
/// Gets a value indicating whether returns whether or not the cache has been initialized.
18+
/// </summary>
19+
/// <returns>True if the cache has been initialized, false otherwise.</returns>
20+
public bool IsInitialized => this.extendedSessions is not null;
21+
1622
/// <summary>
1723
/// Dispose the cache and release all resources.
1824
/// </summary>
@@ -39,13 +45,4 @@ public MemoryCache GetOrInitializeCache(double expirationScanFrequencyInSeconds)
3945

4046
return this.extendedSessions;
4147
}
42-
43-
/// <summary>
44-
/// Returns whether or not the cache has been initialized.
45-
/// </summary>
46-
/// <returns>True if the cache has been initialized, false otherwise.</returns>
47-
public bool IsInitialized()
48-
{
49-
return this.extendedSessions is not null;
50-
}
5148
}

src/Worker/Core/Worker.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The worker is responsible for processing durable task work items.</PackageDescri
99
</PropertyGroup>
1010

1111
<ItemGroup>
12+
<PackageReference Include="Microsoft.Extensions.Caching.Memory" />
1213
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
1314
<PackageReference Include="Microsoft.Extensions.Options" />
1415
<PackageReference Include="System.Text.Json" />

src/Worker/Grpc/GrpcOrchestrationRunner.cs

Lines changed: 9 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -84,50 +84,9 @@ public static string LoadAndRun(
8484
ITaskOrchestrator implementation,
8585
IServiceProvider? services = null)
8686
{
87-
Check.NotNullOrEmpty(encodedOrchestratorRequest);
88-
Check.NotNull(implementation);
89-
90-
P.OrchestratorRequest request = P.OrchestratorRequest.Parser.Base64Decode<P.OrchestratorRequest>(
91-
encodedOrchestratorRequest);
92-
93-
List<HistoryEvent> pastEvents = request.PastEvents.Select(ProtoUtils.ConvertHistoryEvent).ToList();
94-
IEnumerable<HistoryEvent> newEvents = request.NewEvents.Select(ProtoUtils.ConvertHistoryEvent);
95-
Dictionary<string, object?> properties = request.Properties.ToDictionary(
96-
pair => pair.Key,
97-
pair => ProtoUtils.ConvertValueToObject(pair.Value));
98-
99-
// Re-construct the orchestration state from the history.
100-
// New events must be added using the AddEvent method.
101-
OrchestrationRuntimeState runtimeState = new(pastEvents);
102-
foreach (HistoryEvent newEvent in newEvents)
103-
{
104-
runtimeState.AddEvent(newEvent);
105-
}
106-
107-
TaskName orchestratorName = new(runtimeState.Name);
108-
ParentOrchestrationInstance? parent = runtimeState.ParentInstance is ParentInstance p
109-
? new(new(p.Name), p.OrchestrationInstance.InstanceId)
110-
: null;
111-
112-
DurableTaskShimFactory factory = services is null
113-
? DurableTaskShimFactory.Default
114-
: ActivatorUtilities.GetServiceOrCreateInstance<DurableTaskShimFactory>(services);
115-
TaskOrchestration shim = factory.CreateOrchestration(orchestratorName, implementation, properties, parent);
116-
TaskOrchestrationExecutor executor = new(runtimeState, shim, BehaviorOnContinueAsNew.Carryover, request.EntityParameters.ToCore(), ErrorPropagationMode.UseFailureDetails);
117-
OrchestratorExecutionResult result = executor.Execute();
118-
119-
P.OrchestratorResponse response = ProtoUtils.ConstructOrchestratorResponse(
120-
request.InstanceId,
121-
request.ExecutionId,
122-
result.CustomStatus,
123-
result.Actions,
124-
completionToken: string.Empty, /* doesn't apply */
125-
entityConversionState: null,
126-
orchestrationActivity: null);
127-
byte[] responseBytes = response.ToByteArray();
128-
return Convert.ToBase64String(responseBytes);
129-
}
130-
87+
return LoadAndRun(encodedOrchestratorRequest, implementation, services);
88+
}
89+
13190
/// <summary>
13291
/// Deserializes orchestration history from <paramref name="encodedOrchestratorRequest"/> and uses it to resume the
13392
/// orchestrator implemented by <paramref name="implementation"/>.
@@ -136,8 +95,8 @@ public static string LoadAndRun(
13695
/// The encoded protobuf payload representing an orchestration execution request. This is a base64-encoded string.
13796
/// </param>
13897
/// <param name="implementation">
139-
/// An <see cref="ITaskOrchestrator"/> implementation that defines the orchestrator logic.
140-
/// </param>
98+
/// An <see cref="ITaskOrchestrator"/> implementation that defines the orchestrator logic.
99+
/// </param>
141100
/// <param name="extendedSessionsCache">
142101
/// The cache of extended sessions which can be used to retrieve the <see cref="ExtendedSessionState"/> if this orchestration request is from within an extended session.
143102
/// </param>
@@ -155,13 +114,12 @@ public static string LoadAndRun(
155114
/// </exception>
156115
public static string LoadAndRun(
157116
string encodedOrchestratorRequest,
158-
ITaskOrchestrator implementation,
159-
ExtendedSessionsCache extendedSessionsCache,
117+
ITaskOrchestrator implementation,
118+
ExtendedSessionsCache? extendedSessionsCache,
160119
IServiceProvider? services = null)
161120
{
162121
Check.NotNullOrEmpty(encodedOrchestratorRequest);
163-
Check.NotNull(implementation);
164-
Check.NotNull(extendedSessionsCache);
122+
Check.NotNull(implementation);
165123

166124
P.OrchestratorRequest request = P.OrchestratorRequest.Parser.Base64Decode<P.OrchestratorRequest>(
167125
encodedOrchestratorRequest);
@@ -186,7 +144,7 @@ public static string LoadAndRun(
186144
&& extendedSessionIdleTimeout >= 0)
187145
{
188146
extendedSessionIdleTimeoutInSeconds = extendedSessionIdleTimeout;
189-
extendedSessions = extendedSessionsCache.GetOrInitializeCache(extendedSessionIdleTimeoutInSeconds);
147+
extendedSessions = extendedSessionsCache?.GetOrInitializeCache(extendedSessionIdleTimeoutInSeconds);
190148
}
191149

192150
if (properties.TryGetValue("IncludePastEvents", out object? includePastEventsObj)

src/Worker/Grpc/Worker.Grpc.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
<EnableStyleCop>true</EnableStyleCop>
77
</PropertyGroup>
88

9-
<ItemGroup>
10-
<PackageReference Include="Microsoft.Extensions.Caching.Memory" />
11-
</ItemGroup>
12-
139
<ItemGroup>
1410
<ProjectReference Include="../Core/Worker.csproj" />
1511
<ProjectReference Include="../../Abstractions/Abstractions.csproj" />

test/Worker/Core.Tests/Worker.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
<ItemGroup>
1212
<ProjectReference Include="$(SrcRoot)Worker/Core/Worker.csproj" />
13-
<ProjectReference Include="..\..\..\src\Worker\Grpc\Worker.Grpc.csproj" />
1413
</ItemGroup>
1514

1615
</Project>

0 commit comments

Comments
 (0)