/// <summary> /// Initialize constructor parameters /// </summary> public WorkflowEventsProcessorConstructorTest() { _decisionTask = Substitute.For <DecisionTask>(); _pollforDecisionTaskRequest = Substitute.For <PollForDecisionTaskRequest>(); _amazonSwf = Substitute.For <IAmazonSimpleWorkflow>(); _workflowBase = Substitute.For <WorkflowBase>("domain", "workflowName", "version", "taskList", _amazonSwf); }
private List <Decision> Decide(DecisionTask task) { List <Decision> decisions = new List <Decision>(); SwfActivity latestActivity = null; HistoryEvent latestEvent = task.Events[0]; if (latestEvent.EventType == EventType.ActivityTaskCompleted) { latestActivity = JsonSerializer.Deserialize <SwfActivity>(latestEvent.ActivityTaskCompletedEventAttributes.Result); } SwfActivity nextActivity = this.CreateNextEmrActivity(latestActivity); if (nextActivity == null) { decisions.Add(this.CreateCompleteWorkflowExecutionDecision()); } else { decisions.Add(this.CreateActivityDecision(nextActivity)); } return(decisions); }
public WorkflowTests() { _decisionTask = Substitute.For <DecisionTask>(); _decisionTask.WorkflowType = new WorkflowType { Name = "TestWorkflow", Version = "TestVersion" }; _decisionTask.WorkflowExecution = new WorkflowExecution { RunId = "TestRunId", WorkflowId = "" }; var results = new ConcurrentDictionary <int, string>(); results.AddOrUpdate(1, "TestResult", (index, value) => $"{value} - {index}"); _executionContext = WorkflowStateSerializer.Serialize(new WorkflowState() { CurrentStepNumber = 1, NumberOfActions = 1, Results = results }); _pollforDecisionTaskRequest = Substitute.For <PollForDecisionTaskRequest>(); _pollforDecisionTaskRequest.Domain = "TestDomain"; _amazonSwf = Substitute.For <IAmazonSimpleWorkflow>(); _workflow = Substitute.For <WorkflowBase>("domain", _defaultWorkflowName, "version", "taskList", _amazonSwf); }
public MakeDecisionTests() { _decisionTask = Substitute.For <DecisionTask>(); _decisionTask.WorkflowType = new WorkflowType { Name = "TestWorkflow", Version = "TestVersion" }; _decisionTask.WorkflowExecution = new WorkflowExecution { RunId = "TestRunId", WorkflowId = "" }; var results = new ConcurrentDictionary <int, string>(); results.AddOrUpdate(1, "TestResult", (key, value) => $"{key} - {value}"); WorkflowStateSerializer.Serialize(new WorkflowState() { CurrentStepNumber = 1, NumberOfActions = 1, Results = results }); _pollforDecisionTaskRequest = Substitute.For <PollForDecisionTaskRequest>(); _pollforDecisionTaskRequest.Domain = "TestDomain"; _amazonSwf = Substitute.For <IAmazonSimpleWorkflow>(); _workflowBase = Substitute.For <WorkflowBase>("domain", "workflowName", "version", "taskList", _amazonSwf); var describeWorkflowExecutionRequest = Substitute.For <DescribeWorkflowExecutionRequest>(); describeWorkflowExecutionRequest.Domain = _pollforDecisionTaskRequest.Domain; describeWorkflowExecutionRequest.Execution = _decisionTask.WorkflowExecution; }
public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems) { AmazonSimpleWorkflowConfig config = new AmazonSimpleWorkflowConfig(); config.RegionEndpoint = region; ConfigureClient(config); AmazonSimpleWorkflowClient client = new AmazonSimpleWorkflowClient(creds, config); DecisionTask resp = new DecisionTask(); do { PollForDecisionTaskRequest req = new PollForDecisionTaskRequest { NextPageToken = resp.NextPageToken , MaximumPageSize = maxItems }; resp = client.PollForDecisionTask(req); CheckError(resp.HttpStatusCode, "200"); foreach (var obj in resp.Events) { AddObject(obj); } }while (!string.IsNullOrEmpty(resp.NextPageToken)); }
public void Throws_exception_when_first_event_is_not_decision_task_started_event() { var decision1 = new DecisionTask { TaskToken = "t,", NextPageToken = "token", Events = new List <HistoryEvent> { _eventGraphBuilder.WorkflowStartedEvent() } }; var decision2 = new DecisionTask { TaskToken = "t,", NextPageToken = "token1", Events = new List <HistoryEvent> { new HistoryEvent { EventId = 2 } } }; var decision3 = new DecisionTask { TaskToken = "t,", Events = new List <HistoryEvent> { new HistoryEvent { EventId = 3 } } }; AmazonSwfReturnsDecisionTask(decision1, decision2, decision3); Assert.ThrowsAsync <ArgumentException>(async() => await _taskList.PollForWorkflowTaskAsync(_domain, _pollingIdentity, _cancellationTokenSource.Token)); }
void PollAndDecide() { while (!_cancellationToken.IsCancellationRequested) { try { DecisionTask task = Poll(); if (!string.IsNullOrEmpty(task.TaskToken)) { //Create the next set of decision based on the current state and //the execution history var decisions = Decide(task); //Complete the task with the new set of decisions CompleteTaskAsync(task.TaskToken, decisions).Wait(); } } catch (AggregateException e) { var inner = e.InnerException; Logger.LogMessage("Unknown error while processing workflow decisions: {0}\n{1}", inner.Message, inner.StackTrace); } catch (Exception e) { Logger.LogMessage("Unknown error while processing workflow decisions: {0}\n{1}", e.Message, e.StackTrace); } } }
public async Task Task_queue_can_be_configured_to_read_first_page_of_hisotry_events() { var decision1 = new DecisionTask { TaskToken = "t,", NextPageToken = "token", Events = new List <HistoryEvent> { new HistoryEvent { EventId = 1 } } }; var decision2 = new DecisionTask { TaskToken = "t,", NextPageToken = "token1", Events = new List <HistoryEvent> { new HistoryEvent { EventId = 2 } } }; var decision3 = new DecisionTask { TaskToken = "t,", Events = new List <HistoryEvent> { new HistoryEvent { EventId = 3 } } }; AmazonSwfReturnsDecisionTask(decision1, decision2, decision3); _taskList.ReadStrategy = TaskList.ReadFirstPage; var decisionTask = await _taskList.PollForWorkflowTaskAsync(_domain, _pollingIdentity, _cancellationTokenSource.Token); Assert.That(decisionTask, Is.Not.EqualTo(WorkflowTask.Empty)); _amazonWorkflowClient.Verify(c => c.PollForDecisionTaskAsync(It.IsAny <PollForDecisionTaskRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1)); }
public async Task Task_queue_can_be_configured_to_read_first_page_of_hisotry_events() { var decisionStartedEvent = _eventGraphBuilder.DecisionStartedEvent(DateTime.UtcNow); var decision1 = new DecisionTask { TaskToken = "t,", NextPageToken = "token", Events = new List <HistoryEvent> { decisionStartedEvent } }; var decision2 = new DecisionTask { TaskToken = "t,", NextPageToken = "token1", Events = new List <HistoryEvent> { new HistoryEvent { EventId = 2 } } }; var decision3 = new DecisionTask { TaskToken = "t,", Events = new List <HistoryEvent> { new HistoryEvent { EventId = 3 } } }; AmazonSwfReturnsDecisionTask(decision1, decision2, decision3); _taskList.ReadStrategy = TaskList.ReadFirstPage; var workflowTask = await _taskList.PollForWorkflowTaskAsync(_domain, _pollingIdentity, _cancellationTokenSource.Token); Assert.That(workflowTask, Is.Not.EqualTo(WorkflowTask.Empty)); var events = workflowTask.AllEvents.ToArray(); Assert.That(events.Length, Is.EqualTo(1)); Assert.That(events[0].EventId, Is.EqualTo(1)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Before public void setUp() public virtual void setUp() { decisionTask = createElement(casePlanModel, "aDecisionTask", typeof(DecisionTask)); planItem = createElement(casePlanModel, "PI_aHumanTask", typeof(PlanItem)); planItem.Definition = decisionTask; }
public async Task By_default_read_all_events_when_decision_task_is_returned_in_multiple_pages() { var decision1 = new DecisionTask { TaskToken = "t,", NextPageToken = "token", Events = new List <HistoryEvent> { _eventGraphBuilder.DecisionStartedEvent(DateTime.UtcNow) } }; var decision2 = new DecisionTask { TaskToken = "t,", NextPageToken = "token1", Events = new List <HistoryEvent> { new HistoryEvent { EventId = 2 } } }; var decision3 = new DecisionTask { TaskToken = "t,", Events = new List <HistoryEvent> { new HistoryEvent { EventId = 3 } } }; AmazonSwfReturnsDecisionTask(decision1, decision2, decision3); var workflowTask = await _taskList.PollForWorkflowTaskAsync(_domain, _pollingIdentity, _cancellationTokenSource.Token); Assert.That(workflowTask, Is.Not.EqualTo(WorkflowTask.Empty)); var events = workflowTask.AllEvents.ToArray(); Assert.That(events.Length, Is.EqualTo(3)); Assert.That(events[0].EventId, Is.EqualTo(1)); Assert.That(events[1].EventId, Is.EqualTo(2)); Assert.That(events[2].EventId, Is.EqualTo(3)); }
public async Task By_default_read_all_events_when_decision_task_is_returned_in_multiple_pages() { var decision1 = new DecisionTask { TaskToken = "t,", NextPageToken = "token", Events = new List <HistoryEvent> { new HistoryEvent { EventId = 1 } } }; var decision2 = new DecisionTask { TaskToken = "t,", NextPageToken = "token1", Events = new List <HistoryEvent> { new HistoryEvent { EventId = 2 } } }; var decision3 = new DecisionTask { TaskToken = "t,", Events = new List <HistoryEvent> { new HistoryEvent { EventId = 3 } } }; AmazonSwfReturnsDecisionTask(decision1, decision2, decision3); var decisionTask = await _taskList.PollForWorkflowTaskAsync(_domain, _pollingIdentity, _cancellationTokenSource.Token); Assert.That(decisionTask, Is.Not.EqualTo(WorkflowTask.Empty)); _amazonWorkflowClient.Verify(c => c.PollForDecisionTaskAsync(It.IsAny <PollForDecisionTaskRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(3)); }
/// <summary> /// Constructor for the workflow event processor. /// </summary> /// <param name="decisionTask">Decision task passed in from SWF as decision task response.</param> /// <param name="workflow">IEnumerable set of string for workflow name and Type for workflow class.</param> /// <param name="request">The request used to retrieve <paramref name="decisionTask"/>, which will be used to retrieve subsequent history event pages.</param> /// <param name="swfClient">An SWF client.</param> public WorkflowEventsProcessor(DecisionTask decisionTask, WorkflowBase workflow, PollForDecisionTaskRequest request, IAmazonSimpleWorkflow swfClient) { if (decisionTask == null) { throw new ArgumentNullException(nameof(decisionTask)); } if (workflow == null) { throw new ArgumentNullException(nameof(workflow)); } if (request == null) { throw new ArgumentNullException(nameof(request)); } if (swfClient == null) { throw new ArgumentNullException(nameof(swfClient)); } // Store the decision task and allocate a new decision context and event dictionary which // we will use as we walk through the chain of events _decisionTask = decisionTask; _request = request; _decisionContext = new WorkflowDecisionContext(); _swfClient = swfClient; _workflow = workflow; // Set up our events data structure. Events = new WorkflowEventsIterator(ref decisionTask, _request, _swfClient); }
public WorkflowEventsIteratorTest() { _decisionTask = Substitute.For <DecisionTask>(); _pollforDecisionTaskRequest = Substitute.For <PollForDecisionTaskRequest>(); _amazonSwf = Substitute.For <IAmazonSimpleWorkflow>(); var workflowExecutionStartedEventAttributes = Substitute.For <WorkflowExecutionStartedEventAttributes>(); workflowExecutionStartedEventAttributes.Input = "Input"; var workflowExecutionCompletedEventAttributes = Substitute.For <WorkflowExecutionCompletedEventAttributes>(); workflowExecutionCompletedEventAttributes.Result = "Output"; var historyEvent1 = Substitute.For <HistoryEvent>(); historyEvent1.EventId = event1ID; historyEvent1.WorkflowExecutionStartedEventAttributes = workflowExecutionStartedEventAttributes; historyEvent1.EventType = EventType.WorkflowExecutionStarted; var historyEvent2 = Substitute.For <HistoryEvent>(); historyEvent2.EventId = event2ID; historyEvent2.WorkflowExecutionCompletedEventAttributes = Substitute.For <WorkflowExecutionCompletedEventAttributes>(); historyEvent2.EventType = EventType.ChildWorkflowExecutionCompleted; _decisionTask.Events = new List <HistoryEvent> { historyEvent1, historyEvent2 }; }
/// <summary> /// Retrieves the next page of history from /// </summary> /// <returns>The next page of history events.</returns> private List <HistoryEvent> GetNextPage() { var request = new PollForDecisionTaskRequest { Domain = _request.Domain, NextPageToken = _lastResponse.NextPageToken, TaskList = _request.TaskList, MaximumPageSize = _request.MaximumPageSize }; const int retryCount = 10; int currentTry = 1; bool pollFailed; do { pollFailed = false; try { _lastResponse = _swfClient.PollForDecisionTaskAsync(request).Result.DecisionTask; } catch (Exception ex) { Console.Error.WriteLine("Poll request failed with exception: " + ex); pollFailed = true; } currentTry += 1; } while (pollFailed && currentTry <= retryCount); return(_lastResponse.Events); }
private static WorkflowTask ValidatedWorkflowTask(DecisionTask decisionTask, double downloadFactor) { if (decisionTask.Events == null || decisionTask.Events.Count == 0) { throw new ArgumentException("", "decisionTask.Events"); } return(new WorkflowTask(decisionTask, TimeSpan.FromMilliseconds(downloadFactor * decisionTask.Events.Count))); }
/// <summary> /// Create the instance from Amazon SWF DecisionTask. /// </summary> /// <param name="decisionTask"></param> /// <param name="downloadFactor">Indicate how much time it will take in milliseconds to download a history event. By default it assumes it will take 500 ms to download 1000 events.</param> /// <returns></returns> public static WorkflowTask Create(DecisionTask decisionTask, double downloadFactor = .5) { if (HasNewEvents(decisionTask)) { return(ValidatedWorkflowTask(decisionTask, downloadFactor)); } return(Empty); }
/// <summary> /// Initializes a new instance of the <see cref="WorkflowEventsIterator"/> class. /// </summary> /// <param name="decisionTask">Reference to the decision task passed in from </param> /// <param name="request">The request used to retrieve <paramref name="decisionTask"/>, which will be used to retrieve subsequent history event pages.</param> /// <param name="swfClient">An SWF client.</param> public WorkflowEventsIterator(ref DecisionTask decisionTask, PollForDecisionTaskRequest request, IAmazonSimpleWorkflow swfClient) { _lastResponse = decisionTask; _request = request; _swfClient = swfClient; _historyEvents = decisionTask.Events; }
private void AmazonSwfReturns(DecisionTask decisionTask) { _amazonWorkflowClient.SetupSequence(c => c.PollForDecisionTaskAsync(It.IsAny <PollForDecisionTaskRequest>(), It.IsAny <CancellationToken>())) .Returns(Task.FromResult(new PollForDecisionTaskResponse() { DecisionTask = decisionTask })) .Returns(Task.FromResult(new PollForDecisionTaskResponse())); }
public void Invalid_history_events_tests() { var decisionTask = new DecisionTask() { Events = new List <HistoryEvent>(), TaskToken = "token" }; Assert.Throws <ArgumentException>(() => WorkflowTask.Create(decisionTask)); decisionTask.Events = new List <HistoryEvent>(); Assert.Throws <ArgumentException>(() => WorkflowTask.Create(decisionTask)); }
protected async override void DoWorkSafe() { DecisionTask task = await this.Poll(); if (!string.IsNullOrEmpty(task.TaskToken)) { //Create the next set of decision based on the current state of the EMR Job List <Decision> decisions = this.Decide(task); //Complete the task with the new set of decisions await CompleteTask(task.TaskToken, decisions); } }
public WorkflowEventsProcessorTests() { _decisionTask = Substitute.For <DecisionTask>(); _decisionTask.WorkflowType = new WorkflowType { Name = "TestWorkflow", Version = "TestVersion" }; _decisionTask.WorkflowExecution = new WorkflowExecution { RunId = "TestRunId", WorkflowId = "" }; var results = new ConcurrentDictionary <int, string>(); results.AddOrUpdate(1, "TestResult", UpdateValueFactory); _executionContext = WorkflowStateSerializer.Serialize(new WorkflowState() { CurrentStepNumber = 1, NumberOfActions = 1, Results = results }); _pollforDecisionTaskRequest = Substitute.For <PollForDecisionTaskRequest>(); _pollforDecisionTaskRequest.Domain = "TestDomain"; _amazonSwf = Substitute.For <IAmazonSimpleWorkflow>(); _workflowBase = Substitute.For <WorkflowBase>("domain", "workflowName", "version", "taskList", _amazonSwf); var describeWorkflowExecutionRequest = Substitute.For <DescribeWorkflowExecutionRequest>(); describeWorkflowExecutionRequest.Domain = _pollforDecisionTaskRequest.Domain; describeWorkflowExecutionRequest.Execution = _decisionTask.WorkflowExecution; //_amazonSwf.DescribeWorkflowExecution(describeWorkflowExecutionRequest) // .ReturnsForAnyArgs( // info => // new DescribeWorkflowExecutionResponse() // { // HttpStatusCode = HttpStatusCode.OK, // WorkflowExecutionDetail = new WorkflowExecutionDetail() {LatestExecutionContext = _executionContext} // }); SDK.Workflow.WorkflowEventsProcessor processor = Substitute.For <SDK.Workflow.WorkflowEventsProcessor>(_decisionTask, _workflowBase, _pollforDecisionTaskRequest, _amazonSwf); processor.GetLastExecContext().ReturnsForAnyArgs(info => WorkflowStateSerializer.Deserialize(_executionContext)); //_workflowEventsIterator = Substitute.For<WorkflowEventsIterator>(_decisionTask, _pollforDecisionTaskRequest, // _amazonSwf); }
public async Task Decision_task_polling_exception_can_be_handled_to_retry() { var expectedDecisionTask = new DecisionTask(); _amazonWorkflowClient.SetupSequence(s => s.PollForDecisionTaskAsync(It.IsAny <PollForDecisionTaskRequest>(), It.IsAny <CancellationToken>())) .Throws(new UnknownResourceException("not found")) .Returns(Task.FromResult(new PollForDecisionTaskResponse() { DecisionTask = expectedDecisionTask })); var domain = _domain.OnPollingError((e) => ErrorAction.Retry); var decisionTask = await domain.PollForDecisionTaskAsync(_taskList, _pollingIdentity, _cancellationToken); Assert.That(decisionTask, Is.EqualTo(expectedDecisionTask)); }
//TODO : Get rid of this constructor once the dependent constructor is deleted. private WorkflowHistoryEvents(IEnumerable <HistoryEvent> allHistoryEvents, long previousStartedEventId, long newStartedEventId, string workflowRunId) { var decision = new DecisionTask() { PreviousStartedEventId = previousStartedEventId, StartedEventId = newStartedEventId, WorkflowExecution = new WorkflowExecution() { RunId = workflowRunId } }; decision.Events = allHistoryEvents.ToList(); decision.TaskToken = "dummy"; _workflowTask = WorkflowTask.Create(decision); }
public List <Decision> HandleDecisionTask(DecisionTask decisionTask) { _decisions = new List <Decision>(); foreach (var historyEvent in decisionTask.Events) { if (historyEvent.EventId <= decisionTask.PreviousStartedEventId) { continue; } else { var handlerMethodForEventType = this.GetType().GetMethod( historyEvent.EventType, BindingFlags.NonPublic | BindingFlags.Instance); var eventAttributesProperty = historyEvent.GetType().GetProperty(historyEvent.EventType + "EventAttributes"); if (handlerMethodForEventType != null && eventAttributesProperty != null) { try { handlerMethodForEventType.Invoke(this, new object[] { eventAttributesProperty.GetValue(historyEvent), decisionTask }); } catch (Exception ex) { ex = ex.InnerException; _decisions.Clear(); FailWorkflow(new FailWorkflowExecutionDecisionAttributes { Reason = "exception", Details = string.Format("Unhandled exception in {0}: {1}\n\n{2}", handlerMethodForEventType.Name, ex.Message, ex.StackTrace) }); break; } } } } return(_decisions); }
private async Task ExecuteDecisionTaskHandler(Type deciderType, DecisionTask decisionTask) { Exception exception = null; try { using (var decider = (SwfDeciderWorker)_serviceProvider.GetService(deciderType)) { var decisions = decider.HandleDecisionTask(decisionTask); await _workflow.RespondDecisionTaskCompletedAsync(new RespondDecisionTaskCompletedRequest { TaskToken = decisionTask.TaskToken, Decisions = decisions }); } } catch (Exception ex) { exception = ex; } if (exception != null) { await _workflow.RespondDecisionTaskCompletedAsync(new RespondDecisionTaskCompletedRequest { TaskToken = decisionTask.TaskToken, Decisions = new List <Decision> { new Decision { DecisionType = new DecisionType("FailWorkflowExecution"), FailWorkflowExecutionDecisionAttributes = new FailWorkflowExecutionDecisionAttributes { Reason = "exception", Details = string.Format("{0}\n\n{1}", exception.Message, exception.StackTrace) } } } }); } }
public WorkflowHistoryEvents Result() { var totalEvents = _newEvents.Concat(_processedEvents).ToList(); var decisionTask = new DecisionTask() { Events = totalEvents, WorkflowExecution = new WorkflowExecution() { RunId = _workflowRunId, WorkflowId = _workflowId }, TaskToken = "dummy token" }; if (_newEvents.Count > 0) { decisionTask.PreviousStartedEventId = _newEvents.Last().EventId - 1; decisionTask.StartedEventId = _newEvents.First().EventId; } return(new WorkflowHistoryEvents(WorkflowTask.Create(decisionTask))); }
/// <summary> /// Constructor for the workflow event processor. /// </summary> /// <param name="decisionTask">Decision task passed in from SWF as decision task response.</param> /// <param name="workflows">IEnumerable set of string for workflow name and Type for workflow class.</param> /// <param name="request">The request used to retrieve <paramref name="decisionTask"/>, which will be used to retrieve subsequent history event pages.</param> /// <param name="swfClient">An SWF client.</param> public WorkflowEventsProcessor(DecisionTask decisionTask, IEnumerable <KeyValuePair <string, Type> > workflows, PollForDecisionTaskRequest request, IAmazonSimpleWorkflow swfClient) { // Decision task can't be null. if (decisionTask == null) { throw new ArgumentNullException("decisionTask"); } if (request == null) { throw new ArgumentNullException("request"); } // Store the decision task and allocate a new decision context and event dictionary which // we will use as we walk through the chain of events _decisionTask = decisionTask; _request = request; _decisionContext = new WorkflowDecisionContext(); _swfClient = swfClient; // Set up our events data structure _events = new WorkflowEventsIterator(ref decisionTask, _request, _swfClient); _workflows = (Dictionary <string, Type>)workflows; }
private DecisionTask BuildDecisionTask(DateTime decisionTaskTime) { var decisionTask = new DecisionTask() { Events = new List <HistoryEvent>(), TaskToken = "token" }; decisionTask.WorkflowExecution = new WorkflowExecution() { WorkflowId = "wid", RunId = "rid" }; decisionTask.Events.Add(new HistoryEvent() { EventId = 1001, EventType = EventType.DecisionTaskStarted, EventTimestamp = decisionTaskTime }); for (int i = 1000; i > 0; i--) { decisionTask.Events.Add(new HistoryEvent() { EventId = i }); } return(decisionTask); }
public void Setup() { var decisionTask = new DecisionTask() { Events = new List <HistoryEvent>(), TaskToken = "token" }; decisionTask.WorkflowExecution = new WorkflowExecution() { WorkflowId = "wid", RunId = "rid" }; decisionTask.Events.Add(new HistoryEvent() { EventId = 5, EventType = EventType.DecisionTaskStarted }); decisionTask.Events.Add(new HistoryEvent() { EventId = 4 }); decisionTask.Events.Add(new HistoryEvent() { EventId = 3 }); decisionTask.Events.Add(new HistoryEvent() { EventId = 2 }); decisionTask.Events.Add(new HistoryEvent() { EventId = 1 }); decisionTask.PreviousStartedEventId = 2; decisionTask.StartedEventId = 5; _workflowTask = WorkflowTask.Create(decisionTask); }