-
Notifications
You must be signed in to change notification settings - Fork 291
/
TaskOrchestrationContext.cs
663 lines (564 loc) · 28.2 KB
/
TaskOrchestrationContext.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
// ----------------------------------------------------------------------------------
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------
namespace DurableTask.Core
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
using DurableTask.Core.Command;
using DurableTask.Core.Common;
using DurableTask.Core.Exceptions;
using DurableTask.Core.History;
using DurableTask.Core.Serializing;
using DurableTask.Core.Tracing;
internal class TaskOrchestrationContext : OrchestrationContext
{
private readonly IDictionary<int, OpenTaskInfo> openTasks;
private readonly IDictionary<int, OrchestratorAction> orchestratorActionsMap;
private OrchestrationCompleteOrchestratorAction continueAsNew;
private bool executionCompletedOrTerminated;
private int idCounter;
private readonly Queue<HistoryEvent> eventsWhileSuspended;
public bool IsSuspended { get; private set; }
public bool HasContinueAsNew => continueAsNew != null;
public void AddEventToNextIteration(HistoryEvent he)
{
continueAsNew.CarryoverEvents.Add(he);
}
public TaskOrchestrationContext(
OrchestrationInstance orchestrationInstance,
TaskScheduler taskScheduler,
ErrorPropagationMode errorPropagationMode = ErrorPropagationMode.SerializeExceptions)
{
Utils.UnusedParameter(taskScheduler);
this.openTasks = new Dictionary<int, OpenTaskInfo>();
this.orchestratorActionsMap = new SortedDictionary<int, OrchestratorAction>();
this.idCounter = 0;
this.MessageDataConverter = JsonDataConverter.Default;
this.ErrorDataConverter = JsonDataConverter.Default;
OrchestrationInstance = orchestrationInstance;
IsReplaying = false;
ErrorPropagationMode = errorPropagationMode;
this.eventsWhileSuspended = new Queue<HistoryEvent>();
}
public IEnumerable<OrchestratorAction> OrchestratorActions => this.orchestratorActionsMap.Values;
public bool HasOpenTasks => this.openTasks.Count > 0;
internal void ClearPendingActions()
{
this.orchestratorActionsMap.Clear();
continueAsNew = null;
}
public override async Task<TResult> ScheduleTask<TResult>(string name, string version,
params object[] parameters)
{
TResult result = await ScheduleTaskToWorker<TResult>(name, version, null, parameters);
return result;
}
public async Task<TResult> ScheduleTaskToWorker<TResult>(string name, string version, string taskList,
params object[] parameters)
{
object result = await ScheduleTaskInternal(name, version, taskList, typeof(TResult), parameters);
if (result == null)
{
return default(TResult);
}
return (TResult)result;
}
public async Task<object> ScheduleTaskInternal(string name, string version, string taskList, Type resultType,
params object[] parameters)
{
int id = this.idCounter++;
string serializedInput = this.MessageDataConverter.Serialize(parameters);
var scheduleTaskTaskAction = new ScheduleTaskOrchestratorAction
{
Id = id,
Name = name,
Version = version,
Tasklist = taskList,
Input = serializedInput,
};
this.orchestratorActionsMap.Add(id, scheduleTaskTaskAction);
var tcs = new TaskCompletionSource<string>();
this.openTasks.Add(id, new OpenTaskInfo { Name = name, Version = version, Result = tcs });
string serializedResult = await tcs.Task;
return this.MessageDataConverter.Deserialize(serializedResult, resultType);
}
public override Task<T> CreateSubOrchestrationInstance<T>(
string name,
string version,
string instanceId,
object input)
{
return CreateSubOrchestrationInstanceCore<T>(name, version, instanceId, input, null);
}
public override Task<T> CreateSubOrchestrationInstance<T>(
string name,
string version,
string instanceId,
object input,
IDictionary<string, string> tags)
{
return CreateSubOrchestrationInstanceCore<T>(name, version, instanceId, input, tags);
}
public override Task<T> CreateSubOrchestrationInstance<T>(
string name,
string version,
object input)
{
return CreateSubOrchestrationInstanceCore<T>(name, version, null, input, null);
}
async Task<T> CreateSubOrchestrationInstanceCore<T>(
string name,
string version,
string instanceId,
object input,
IDictionary<string, string> tags)
{
int id = this.idCounter++;
string serializedInput = this.MessageDataConverter.Serialize(input);
string actualInstanceId = instanceId;
if (string.IsNullOrWhiteSpace(actualInstanceId))
{
actualInstanceId = OrchestrationInstance.ExecutionId + ":" + id;
}
var action = new CreateSubOrchestrationAction
{
Id = id,
InstanceId = actualInstanceId,
Name = name,
Version = version,
Input = serializedInput,
Tags = tags
};
this.orchestratorActionsMap.Add(id, action);
if (OrchestrationTags.IsTaggedAsFireAndForget(tags))
{
// this is a fire-and-forget orchestration, so we do not wait for a result.
return default(T);
}
else
{
var tcs = new TaskCompletionSource<string>();
this.openTasks.Add(id, new OpenTaskInfo { Name = name, Version = version, Result = tcs });
string serializedResult = await tcs.Task;
return this.MessageDataConverter.Deserialize<T>(serializedResult);
}
}
public override void SendEvent(OrchestrationInstance orchestrationInstance, string eventName, object eventData)
{
if (string.IsNullOrWhiteSpace(orchestrationInstance?.InstanceId))
{
throw new ArgumentException(nameof(orchestrationInstance));
}
int id = this.idCounter++;
string serializedEventData = this.MessageDataConverter.Serialize(eventData);
var action = new SendEventOrchestratorAction
{
Id = id,
Instance = orchestrationInstance,
EventName = eventName,
EventData = serializedEventData,
};
this.orchestratorActionsMap.Add(id, action);
}
public override void ContinueAsNew(object input)
{
ContinueAsNew(null, input);
}
public override void ContinueAsNew(string newVersion, object input)
{
ContinueAsNewCore(newVersion, input);
}
void ContinueAsNewCore(string newVersion, object input)
{
string serializedInput = this.MessageDataConverter.Serialize(input);
this.continueAsNew = new OrchestrationCompleteOrchestratorAction
{
Result = serializedInput,
OrchestrationStatus = OrchestrationStatus.ContinuedAsNew,
NewVersion = newVersion
};
}
public override Task<T> CreateTimer<T>(DateTime fireAt, T state)
{
return CreateTimer(fireAt, state, CancellationToken.None);
}
public override async Task<T> CreateTimer<T>(DateTime fireAt, T state, CancellationToken cancelToken)
{
int id = this.idCounter++;
var createTimerOrchestratorAction = new CreateTimerOrchestratorAction
{
Id = id,
FireAt = fireAt,
};
this.orchestratorActionsMap.Add(id, createTimerOrchestratorAction);
var tcs = new TaskCompletionSource<string>();
this.openTasks.Add(id, new OpenTaskInfo { Name = null, Version = null, Result = tcs });
if (cancelToken != CancellationToken.None)
{
cancelToken.Register(s =>
{
if (tcs.TrySetCanceled())
{
// TODO: Emit a log message that the timer is cancelled.
this.openTasks.Remove(id);
}
}, tcs);
}
await tcs.Task;
return state;
}
public void HandleTaskScheduledEvent(TaskScheduledEvent scheduledEvent)
{
int taskId = scheduledEvent.EventId;
if (!this.orchestratorActionsMap.ContainsKey(taskId))
{
throw new NonDeterministicOrchestrationException(scheduledEvent.EventId,
$"A previous execution of this orchestration scheduled an activity task with sequence ID {taskId} and name "
+ $"'{scheduledEvent.Name}' (version '{scheduledEvent.Version}'), but the current replay execution hasn't "
+ "(yet?) scheduled this task. Was a change made to the orchestrator code after this instance had already "
+ "started running?");
}
var orchestrationAction = this.orchestratorActionsMap[taskId];
if (orchestrationAction is not ScheduleTaskOrchestratorAction currentReplayAction)
{
throw new NonDeterministicOrchestrationException(scheduledEvent.EventId,
$"A previous execution of this orchestration scheduled an activity task with sequence number {taskId} named "
+ $"'{scheduledEvent.Name}', but the current orchestration replay instead produced a "
+ $"{orchestrationAction.GetType().Name} action with this sequence number. Was a change made to the "
+ "orchestrator code after this instance had already started running?");
}
if (!string.Equals(scheduledEvent.Name, currentReplayAction.Name, StringComparison.OrdinalIgnoreCase))
{
throw new NonDeterministicOrchestrationException(scheduledEvent.EventId,
$"A previous execution of this orchestration scheduled an activity task with sequence number {taskId} "
+ $"named '{scheduledEvent.Name}', but the current orchestration replay instead scheduled an activity "
+ $"task named '{currentReplayAction.Name}' with this sequence number. Was a change made to the "
+ "orchestrator code after this instance had already started running?");
}
this.orchestratorActionsMap.Remove(taskId);
}
public void HandleTimerCreatedEvent(TimerCreatedEvent timerCreatedEvent)
{
int taskId = timerCreatedEvent.EventId;
if (taskId == FrameworkConstants.FakeTimerIdToSplitDecision)
{
// This is our dummy timer to split decision for avoiding 100 messages per transaction service bus limit
return;
}
if (!this.orchestratorActionsMap.ContainsKey(taskId))
{
throw new NonDeterministicOrchestrationException(timerCreatedEvent.EventId,
$"A previous execution of this orchestration scheduled a timer task with sequence number {taskId} but "
+ "the current replay execution hasn't (yet?) scheduled this task. Was a change made to the orchestrator "
+ "code after this instance had already started running?");
}
var orchestrationAction = this.orchestratorActionsMap[taskId];
if (orchestrationAction is not CreateTimerOrchestratorAction)
{
throw new NonDeterministicOrchestrationException(timerCreatedEvent.EventId,
$"A previous execution of this orchestration scheduled a timer task with sequence number {taskId} named "
+ $"but the current orchestration replay instead produced a {orchestrationAction.GetType().Name} action with "
+ "this sequence number. Was a change made to the orchestrator code after this instance had already "
+ "started running?");
}
this.orchestratorActionsMap.Remove(taskId);
}
public void HandleSubOrchestrationCreatedEvent(SubOrchestrationInstanceCreatedEvent subOrchestrationCreateEvent)
{
int taskId = subOrchestrationCreateEvent.EventId;
if (!this.orchestratorActionsMap.ContainsKey(taskId))
{
throw new NonDeterministicOrchestrationException(subOrchestrationCreateEvent.EventId,
$"A previous execution of this orchestration scheduled a sub-orchestration task with sequence ID {taskId} "
+ $"and name '{subOrchestrationCreateEvent.Name}' (version '{subOrchestrationCreateEvent.Version}', "
+ $"instance ID '{subOrchestrationCreateEvent.InstanceId}'), but the current replay execution hasn't (yet?) "
+ "scheduled this task. Was a change made to the orchestrator code after this instance had already started running?");
}
var orchestrationAction = this.orchestratorActionsMap[taskId];
if (orchestrationAction is not CreateSubOrchestrationAction currentReplayAction)
{
throw new NonDeterministicOrchestrationException(subOrchestrationCreateEvent.EventId,
$"A previous execution of this orchestration scheduled a sub-orchestration task with sequence ID {taskId} "
+ $"and name '{subOrchestrationCreateEvent.Name}' (version '{subOrchestrationCreateEvent.Version}', "
+ $"instance ID '{subOrchestrationCreateEvent.InstanceId}'), but the current orchestration replay instead "
+ $"produced a {orchestrationAction.GetType().Name} action at this sequence number. Was a change made to "
+ "the orchestrator code after this instance had already started running?");
}
if (!string.Equals(subOrchestrationCreateEvent.Name, currentReplayAction.Name, StringComparison.OrdinalIgnoreCase))
{
throw new NonDeterministicOrchestrationException(subOrchestrationCreateEvent.EventId,
$"A previous execution of this orchestration scheduled a sub-orchestration task with sequence ID {taskId} "
+ $"and name '{subOrchestrationCreateEvent.Name}' (version '{subOrchestrationCreateEvent.Version}', "
+ $"instance ID '{subOrchestrationCreateEvent.InstanceId}'), but the current orchestration replay instead "
+ $"scheduled a sub-orchestration task with name {currentReplayAction.Name} at this sequence number. "
+ "Was a change made to the orchestrator code after this instance had already started running?");
}
this.orchestratorActionsMap.Remove(taskId);
}
public void HandleEventSentEvent(EventSentEvent eventSentEvent)
{
int taskId = eventSentEvent.EventId;
if (!this.orchestratorActionsMap.ContainsKey(taskId))
{
throw new NonDeterministicOrchestrationException(eventSentEvent.EventId,
$"A previous execution of this orchestration scheduled a send event task with sequence ID {taskId}, "
+ $"type '{eventSentEvent.EventType}' name '{eventSentEvent.Name}', instance ID '{eventSentEvent.InstanceId}', "
+ $"but the current replay execution hasn't (yet?) scheduled this task. Was a change made to the orchestrator code "
+ $"after this instance had already started running?");
}
var orchestrationAction = this.orchestratorActionsMap[taskId];
if (!(orchestrationAction is SendEventOrchestratorAction currentReplayAction))
{
throw new NonDeterministicOrchestrationException(eventSentEvent.EventId,
$"A previous execution of this orchestration scheduled a send event task with sequence ID {taskId}, "
+ $"type '{eventSentEvent.EventType}', name '{eventSentEvent.Name}', instance ID '{eventSentEvent.InstanceId}', "
+ $"but the current orchestration replay instead scheduled a {orchestrationAction.GetType().Name} task "
+ "at this sequence number. Was a change made to the orchestrator code after this instance had already "
+ "started running?");
}
if (!string.Equals(eventSentEvent.Name, currentReplayAction.EventName, StringComparison.OrdinalIgnoreCase))
{
throw new NonDeterministicOrchestrationException(eventSentEvent.EventId,
$"A previous execution of this orchestration scheduled a send event task with sequence ID {taskId}, "
+ $"type '{eventSentEvent.EventType}', name '{eventSentEvent.Name}', instance ID '{eventSentEvent.InstanceId}'), "
+ $"but the current orchestration replay instead scheduled a send event task with name {currentReplayAction.EventName}"
+ "at this sequence number. Was a change made to the orchestrator code after this instance had already "
+ "started running?");
}
this.orchestratorActionsMap.Remove(taskId);
}
public void HandleEventRaisedEvent(EventRaisedEvent eventRaisedEvent, bool skipCarryOverEvents, TaskOrchestration taskOrchestration)
{
if (skipCarryOverEvents || !this.HasContinueAsNew)
{
taskOrchestration.RaiseEvent(this, eventRaisedEvent.Name, eventRaisedEvent.Input);
}
else
{
this.AddEventToNextIteration(eventRaisedEvent);
}
}
public void HandleTaskCompletedEvent(TaskCompletedEvent completedEvent)
{
int taskId = completedEvent.TaskScheduledId;
if (this.openTasks.ContainsKey(taskId))
{
OpenTaskInfo info = this.openTasks[taskId];
info.Result.SetResult(completedEvent.Result);
this.openTasks.Remove(taskId);
}
else
{
LogDuplicateEvent("TaskCompleted", completedEvent, taskId);
}
}
public void HandleTaskFailedEvent(TaskFailedEvent failedEvent)
{
int taskId = failedEvent.TaskScheduledId;
if (this.openTasks.ContainsKey(taskId))
{
OpenTaskInfo info = this.openTasks[taskId];
// When using ErrorPropagationMode.SerializeExceptions the "cause" is deserialized from history.
// This isn't fully reliable because not all exception types can be serialized/deserialized.
// When using ErrorPropagationMode.UseFailureDetails we instead use FailureDetails to convey
// error information, which doesn't involve any serialization at all.
Exception cause = this.ErrorPropagationMode == ErrorPropagationMode.SerializeExceptions ?
Utils.RetrieveCause(failedEvent.Details, this.ErrorDataConverter) :
null;
var taskFailedException = new TaskFailedException(
failedEvent.EventId,
taskId,
info.Name,
info.Version,
failedEvent.Reason,
cause);
taskFailedException.FailureDetails = failedEvent.FailureDetails;
TaskCompletionSource<string> tcs = info.Result;
tcs.SetException(taskFailedException);
this.openTasks.Remove(taskId);
}
else
{
LogDuplicateEvent("TaskFailed", failedEvent, taskId);
}
}
public void HandleSubOrchestrationInstanceCompletedEvent(SubOrchestrationInstanceCompletedEvent completedEvent)
{
int taskId = completedEvent.TaskScheduledId;
if (this.openTasks.ContainsKey(taskId))
{
OpenTaskInfo info = this.openTasks[taskId];
info.Result.SetResult(completedEvent.Result);
this.openTasks.Remove(taskId);
}
else
{
LogDuplicateEvent("SubOrchestrationInstanceCompleted", completedEvent, taskId);
}
}
public void HandleSubOrchestrationInstanceFailedEvent(SubOrchestrationInstanceFailedEvent failedEvent)
{
int taskId = failedEvent.TaskScheduledId;
if (this.openTasks.ContainsKey(taskId))
{
OpenTaskInfo info = this.openTasks[taskId];
// When using ErrorPropagationMode.SerializeExceptions the "cause" is deserialized from history.
// This isn't fully reliable because not all exception types can be serialized/deserialized.
// When using ErrorPropagationMode.UseFailureDetails we instead use FailureDetails to convey
// error information, which doesn't involve any serialization at all.
Exception cause = this.ErrorPropagationMode == ErrorPropagationMode.SerializeExceptions ?
Utils.RetrieveCause(failedEvent.Details, this.ErrorDataConverter) :
null;
var failedException = new SubOrchestrationFailedException(failedEvent.EventId, taskId, info.Name,
info.Version,
failedEvent.Reason, cause);
failedException.FailureDetails = failedEvent.FailureDetails;
TaskCompletionSource<string> tcs = info.Result;
tcs.SetException(failedException);
this.openTasks.Remove(taskId);
}
else
{
LogDuplicateEvent("SubOrchestrationInstanceFailed", failedEvent, taskId);
}
}
public void HandleTimerFiredEvent(TimerFiredEvent timerFiredEvent)
{
int taskId = timerFiredEvent.TimerId;
if (this.openTasks.ContainsKey(taskId))
{
OpenTaskInfo info = this.openTasks[taskId];
info.Result.SetResult(timerFiredEvent.TimerId.ToString());
this.openTasks.Remove(taskId);
}
else
{
LogDuplicateEvent("TimerFired", timerFiredEvent, taskId);
}
}
private void LogDuplicateEvent(string source, HistoryEvent historyEvent, int taskId)
{
TraceHelper.TraceSession(
TraceEventType.Warning,
"TaskOrchestrationContext-DuplicateEvent",
OrchestrationInstance.InstanceId,
"Duplicate {0} Event: {1}, type: {2}, ts: {3}",
source,
taskId.ToString(),
historyEvent.EventType,
historyEvent.Timestamp.ToString(CultureInfo.InvariantCulture));
}
public void HandleExecutionTerminatedEvent(ExecutionTerminatedEvent terminatedEvent)
{
CompleteOrchestration(terminatedEvent.Input, null, OrchestrationStatus.Terminated);
}
public void CompleteOrchestration(string result)
{
CompleteOrchestration(result, null, OrchestrationStatus.Completed);
}
public void HandleEventWhileSuspended(HistoryEvent historyEvent)
{
if (historyEvent.EventType != EventType.ExecutionSuspended)
{
this.eventsWhileSuspended.Enqueue(historyEvent);
}
}
public void HandleExecutionSuspendedEvent(ExecutionSuspendedEvent suspendedEvent)
{
this.IsSuspended = true;
}
public void HandleExecutionResumedEvent(ExecutionResumedEvent resumedEvent, Action<HistoryEvent> eventProcessor)
{
this.IsSuspended = false;
while (eventsWhileSuspended.Count > 0)
{
eventProcessor(eventsWhileSuspended.Dequeue());
}
}
public void FailOrchestration(Exception failure)
{
if (failure == null)
{
throw new ArgumentNullException(nameof(failure));
}
string reason = failure.Message;
// string details is legacy, FailureDetails is the newer way to share failure information
string details = null;
FailureDetails failureDetails = null;
// correlation
CorrelationTraceClient.Propagate(
() =>
{
CorrelationTraceClient.TrackException(failure);
});
if (failure is OrchestrationFailureException orchestrationFailureException)
{
if (this.ErrorPropagationMode == ErrorPropagationMode.UseFailureDetails)
{
// When not serializing exceptions, we instead construct FailureDetails objects
failureDetails = orchestrationFailureException.FailureDetails;
}
else
{
details = orchestrationFailureException.Details;
}
}
else
{
if (this.ErrorPropagationMode == ErrorPropagationMode.UseFailureDetails)
{
failureDetails = new FailureDetails(failure);
}
else
{
details = $"Unhandled exception while executing orchestration: {failure}\n\t{failure.StackTrace}";
}
}
CompleteOrchestration(reason, details, OrchestrationStatus.Failed, failureDetails);
}
public void CompleteOrchestration(string result, string details, OrchestrationStatus orchestrationStatus, FailureDetails failureDetails = null)
{
int id = this.idCounter++;
OrchestrationCompleteOrchestratorAction completedOrchestratorAction;
if (orchestrationStatus == OrchestrationStatus.Completed && this.continueAsNew != null)
{
completedOrchestratorAction = this.continueAsNew;
}
else
{
if (this.executionCompletedOrTerminated)
{
return;
}
this.executionCompletedOrTerminated = true;
completedOrchestratorAction = new OrchestrationCompleteOrchestratorAction();
completedOrchestratorAction.Result = result;
completedOrchestratorAction.Details = details;
completedOrchestratorAction.OrchestrationStatus = orchestrationStatus;
completedOrchestratorAction.FailureDetails = failureDetails;
}
completedOrchestratorAction.Id = id;
this.orchestratorActionsMap.Add(id, completedOrchestratorAction);
}
class OpenTaskInfo
{
public string Name { get; set; }
public string Version { get; set; }
public TaskCompletionSource<string> Result { get; set; }
}
}
}