Skip to content

Commit 306dd39

Browse files
author
Sophia Tevosyan
committed
addressing some comments
1 parent 0def003 commit 306dd39

File tree

3 files changed

+124
-118
lines changed

3 files changed

+124
-118
lines changed

src/Shared/Grpc/ProtoUtils.cs

Lines changed: 119 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -295,147 +295,149 @@ internal static P.OrchestratorResponse ConstructOrchestratorResponse(
295295
};
296296

297297
// If a history is required and the orchestration request was not completed, then there is no list of actions.
298-
if (!requiresHistory)
298+
if (requiresHistory)
299299
{
300-
Check.NotNull(actions);
301-
foreach (OrchestratorAction action in actions)
302-
{
303-
var protoAction = new P.OrchestratorAction { Id = action.Id };
300+
return response;
301+
}
304302

305-
switch (action.OrchestratorActionType)
306-
{
307-
case OrchestratorActionType.ScheduleOrchestrator:
308-
var scheduleTaskAction = (ScheduleTaskOrchestratorAction)action;
309-
protoAction.ScheduleTask = new P.ScheduleTaskAction
310-
{
311-
Name = scheduleTaskAction.Name,
312-
Version = scheduleTaskAction.Version,
313-
Input = scheduleTaskAction.Input,
314-
};
303+
Check.NotNull(actions);
304+
foreach (OrchestratorAction action in actions)
305+
{
306+
var protoAction = new P.OrchestratorAction { Id = action.Id };
315307

316-
if (scheduleTaskAction.Tags != null)
317-
{
318-
foreach (KeyValuePair<string, string> tag in scheduleTaskAction.Tags)
319-
{
320-
protoAction.ScheduleTask.Tags[tag.Key] = tag.Value;
321-
}
322-
}
308+
switch (action.OrchestratorActionType)
309+
{
310+
case OrchestratorActionType.ScheduleOrchestrator:
311+
var scheduleTaskAction = (ScheduleTaskOrchestratorAction)action;
312+
protoAction.ScheduleTask = new P.ScheduleTaskAction
313+
{
314+
Name = scheduleTaskAction.Name,
315+
Version = scheduleTaskAction.Version,
316+
Input = scheduleTaskAction.Input,
317+
};
323318

324-
break;
325-
case OrchestratorActionType.CreateSubOrchestration:
326-
var subOrchestrationAction = (CreateSubOrchestrationAction)action;
327-
protoAction.CreateSubOrchestration = new P.CreateSubOrchestrationAction
328-
{
329-
Input = subOrchestrationAction.Input,
330-
InstanceId = subOrchestrationAction.InstanceId,
331-
Name = subOrchestrationAction.Name,
332-
Version = subOrchestrationAction.Version,
333-
};
334-
break;
335-
case OrchestratorActionType.CreateTimer:
336-
var createTimerAction = (CreateTimerOrchestratorAction)action;
337-
protoAction.CreateTimer = new P.CreateTimerAction
338-
{
339-
FireAt = createTimerAction.FireAt.ToTimestamp(),
340-
};
341-
break;
342-
case OrchestratorActionType.SendEvent:
343-
var sendEventAction = (SendEventOrchestratorAction)action;
344-
if (sendEventAction.Instance == null)
319+
if (scheduleTaskAction.Tags != null)
320+
{
321+
foreach (KeyValuePair<string, string> tag in scheduleTaskAction.Tags)
345322
{
346-
throw new ArgumentException(
347-
$"{nameof(SendEventOrchestratorAction)} cannot have a null Instance property!");
323+
protoAction.ScheduleTask.Tags[tag.Key] = tag.Value;
348324
}
325+
}
349326

350-
if (entityConversionState is not null
351-
&& DTCore.Common.Entities.IsEntityInstance(sendEventAction.Instance.InstanceId)
352-
&& sendEventAction.EventName is not null
353-
&& sendEventAction.EventData is not null)
354-
{
355-
P.SendEntityMessageAction sendAction = new P.SendEntityMessageAction();
356-
protoAction.SendEntityMessage = sendAction;
327+
break;
328+
case OrchestratorActionType.CreateSubOrchestration:
329+
var subOrchestrationAction = (CreateSubOrchestrationAction)action;
330+
protoAction.CreateSubOrchestration = new P.CreateSubOrchestrationAction
331+
{
332+
Input = subOrchestrationAction.Input,
333+
InstanceId = subOrchestrationAction.InstanceId,
334+
Name = subOrchestrationAction.Name,
335+
Version = subOrchestrationAction.Version,
336+
};
337+
break;
338+
case OrchestratorActionType.CreateTimer:
339+
var createTimerAction = (CreateTimerOrchestratorAction)action;
340+
protoAction.CreateTimer = new P.CreateTimerAction
341+
{
342+
FireAt = createTimerAction.FireAt.ToTimestamp(),
343+
};
344+
break;
345+
case OrchestratorActionType.SendEvent:
346+
var sendEventAction = (SendEventOrchestratorAction)action;
347+
if (sendEventAction.Instance == null)
348+
{
349+
throw new ArgumentException(
350+
$"{nameof(SendEventOrchestratorAction)} cannot have a null Instance property!");
351+
}
352+
353+
if (entityConversionState is not null
354+
&& DTCore.Common.Entities.IsEntityInstance(sendEventAction.Instance.InstanceId)
355+
&& sendEventAction.EventName is not null
356+
&& sendEventAction.EventData is not null)
357+
{
358+
P.SendEntityMessageAction sendAction = new P.SendEntityMessageAction();
359+
protoAction.SendEntityMessage = sendAction;
357360

358-
EntityConversions.DecodeEntityMessageAction(
359-
sendEventAction.EventName,
360-
sendEventAction.EventData,
361-
sendEventAction.Instance.InstanceId,
362-
sendAction,
363-
out string requestId);
361+
EntityConversions.DecodeEntityMessageAction(
362+
sendEventAction.EventName,
363+
sendEventAction.EventData,
364+
sendEventAction.Instance.InstanceId,
365+
sendAction,
366+
out string requestId);
364367

365-
entityConversionState.EntityRequestIds.Add(requestId);
368+
entityConversionState.EntityRequestIds.Add(requestId);
366369

367-
switch (sendAction.EntityMessageTypeCase)
368-
{
369-
case P.SendEntityMessageAction.EntityMessageTypeOneofCase.EntityLockRequested:
370-
entityConversionState.AddUnlockObligations(sendAction.EntityLockRequested);
371-
break;
372-
case P.SendEntityMessageAction.EntityMessageTypeOneofCase.EntityUnlockSent:
373-
entityConversionState.RemoveUnlockObligation(sendAction.EntityUnlockSent.TargetInstanceId);
374-
break;
375-
default:
376-
break;
377-
}
378-
}
379-
else
370+
switch (sendAction.EntityMessageTypeCase)
380371
{
381-
protoAction.SendEvent = new P.SendEventAction
382-
{
383-
Instance = sendEventAction.Instance.ToProtobuf(),
384-
Name = sendEventAction.EventName,
385-
Data = sendEventAction.EventData,
386-
};
372+
case P.SendEntityMessageAction.EntityMessageTypeOneofCase.EntityLockRequested:
373+
entityConversionState.AddUnlockObligations(sendAction.EntityLockRequested);
374+
break;
375+
case P.SendEntityMessageAction.EntityMessageTypeOneofCase.EntityUnlockSent:
376+
entityConversionState.RemoveUnlockObligation(sendAction.EntityUnlockSent.TargetInstanceId);
377+
break;
378+
default:
379+
break;
387380
}
381+
}
382+
else
383+
{
384+
protoAction.SendEvent = new P.SendEventAction
385+
{
386+
Instance = sendEventAction.Instance.ToProtobuf(),
387+
Name = sendEventAction.EventName,
388+
Data = sendEventAction.EventData,
389+
};
390+
}
388391

389-
break;
390-
case OrchestratorActionType.OrchestrationComplete:
392+
break;
393+
case OrchestratorActionType.OrchestrationComplete:
391394

392-
if (entityConversionState is not null)
395+
if (entityConversionState is not null)
396+
{
397+
// as a precaution, unlock any entities that were not unlocked for some reason, before
398+
// completing the orchestration.
399+
foreach ((string target, string criticalSectionId) in entityConversionState.ResetObligations())
393400
{
394-
// as a precaution, unlock any entities that were not unlocked for some reason, before
395-
// completing the orchestration.
396-
foreach ((string target, string criticalSectionId) in entityConversionState.ResetObligations())
401+
response.Actions.Add(new P.OrchestratorAction
397402
{
398-
response.Actions.Add(new P.OrchestratorAction
403+
Id = action.Id,
404+
SendEntityMessage = new P.SendEntityMessageAction
399405
{
400-
Id = action.Id,
401-
SendEntityMessage = new P.SendEntityMessageAction
406+
EntityUnlockSent = new P.EntityUnlockSentEvent
402407
{
403-
EntityUnlockSent = new P.EntityUnlockSentEvent
404-
{
405-
CriticalSectionId = criticalSectionId,
406-
TargetInstanceId = target,
407-
ParentInstanceId = entityConversionState.CurrentInstance?.InstanceId,
408-
},
408+
CriticalSectionId = criticalSectionId,
409+
TargetInstanceId = target,
410+
ParentInstanceId = entityConversionState.CurrentInstance?.InstanceId,
409411
},
410-
});
411-
}
412+
},
413+
});
412414
}
415+
}
413416

414-
var completeAction = (OrchestrationCompleteOrchestratorAction)action;
415-
protoAction.CompleteOrchestration = new P.CompleteOrchestrationAction
416-
{
417-
CarryoverEvents =
418-
{
419-
// TODO
420-
},
421-
Details = completeAction.Details,
422-
NewVersion = completeAction.NewVersion,
423-
OrchestrationStatus = completeAction.OrchestrationStatus.ToProtobuf(),
424-
Result = completeAction.Result,
425-
};
426-
427-
if (completeAction.OrchestrationStatus == OrchestrationStatus.Failed)
428-
{
429-
protoAction.CompleteOrchestration.FailureDetails = completeAction.FailureDetails.ToProtobuf();
430-
}
417+
var completeAction = (OrchestrationCompleteOrchestratorAction)action;
418+
protoAction.CompleteOrchestration = new P.CompleteOrchestrationAction
419+
{
420+
CarryoverEvents =
421+
{
422+
// TODO
423+
},
424+
Details = completeAction.Details,
425+
NewVersion = completeAction.NewVersion,
426+
OrchestrationStatus = completeAction.OrchestrationStatus.ToProtobuf(),
427+
Result = completeAction.Result,
428+
};
431429

432-
break;
433-
default:
434-
throw new NotSupportedException($"Unknown orchestrator action: {action.OrchestratorActionType}");
435-
}
430+
if (completeAction.OrchestrationStatus == OrchestrationStatus.Failed)
431+
{
432+
protoAction.CompleteOrchestration.FailureDetails = completeAction.FailureDetails.ToProtobuf();
433+
}
436434

437-
response.Actions.Add(protoAction);
435+
break;
436+
default:
437+
throw new NotSupportedException($"Unknown orchestrator action: {action.OrchestratorActionType}");
438438
}
439+
440+
response.Actions.Add(protoAction);
439441
}
440442

441443
return response;

src/Worker/Grpc/GrpcOrchestrationRunner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public static string LoadAndRun(
185185
extendedSessionIdleTimeoutInSeconds = extendedSessionIdleTimeout;
186186
extendedSessions = extendedSessionsCache.GetOrInitializeCache(extendedSessionIdleTimeoutInSeconds);
187187

188-
if (extendedSessions.TryGetValue(request.InstanceId, out ExtendedSessionState? extendedSessionState))
188+
if (extendedSessions.TryGetValue(request.InstanceId, out ExtendedSessionState? extendedSessionState) && extendedSessionState is not null)
189189
{
190190
OrchestrationRuntimeState runtimeState = extendedSessionState!.RuntimeState;
191191
runtimeState.NewEvents.Clear();

src/Worker/Grpc/Worker.Grpc.csproj

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

9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.Extensions.Caching.Memory" />
11+
</ItemGroup>
12+
913
<ItemGroup>
1014
<ProjectReference Include="../Core/Worker.csproj" />
1115
<ProjectReference Include="../../Abstractions/Abstractions.csproj" />

0 commit comments

Comments
 (0)