protected RespondDecisionTaskCompletedRequest StartTimer(WorkflowTimerSetupContext timer) { var attributes = new StartTimerDecisionAttributes { TimerId = timer.TimerId, StartToFireTimeout = timer.StartToFireTimeoutInSeconds.ToString(), Control = timer.Control }; var decisionRequest = new RespondDecisionTaskCompletedRequest { Decisions = new List <Decision> { new Decision { DecisionType = "StartTimer", StartTimerDecisionAttributes = attributes } } }; Debug.WriteLine(">>> Decision: StartTimer " + attributes.TimerId + " (elapses in " + attributes.StartToFireTimeout + " seconds)"); return(decisionRequest); }
/// <summary> /// Copletes the workflow with a failed status /// </summary> /// <param name="error">The error that the workflow failed with</param> /// <returns></returns> public async Task FailWorkflowAsync(object error) { var workflowContext = await GetCurrentContext(); if (workflowContext != null) { var decisionRequest = new RespondDecisionTaskCompletedRequest { TaskToken = workflowContext.ReferenceToken, Decisions = new List <Decision> { new Decision { DecisionType = DecisionType.FailWorkflowExecution, FailWorkflowExecutionDecisionAttributes = new FailWorkflowExecutionDecisionAttributes { Details = JsonConvert.SerializeObject(error) } } } }; await _amazonSimpleWorkflowClient.RespondDecisionTaskCompletedAsync(decisionRequest); await _store.SetStatus(_orchestrationId, Status.FAILED); } }
ActivityTask startActivity(string runId) { var pollDeciderRequest = new PollForDecisionTaskRequest() { Domain = DOMAIN, TaskList = TASKLIST, Identity = "testdecider" }; var pollDeciderResponse = Client.PollForDecisionTask(pollDeciderRequest); var task = pollDeciderResponse.DecisionTask; var respondRequest = new RespondDecisionTaskCompletedRequest() { TaskToken = task.TaskToken, Decisions = new List <Decision>() { new Decision() { DecisionType = "ScheduleActivityTask", ScheduleActivityTaskDecisionAttributes = new ScheduleActivityTaskDecisionAttributes() { ActivityType = ACTIVITY_TYPE, ActivityId = DateTime.Now.Ticks.ToString(), TaskList = TASKLIST } } } }; Client.RespondDecisionTaskCompleted(respondRequest); return(pollActivity()); }
/// <summary> /// Helper method to create an empty decision request. /// </summary> /// <returns>Properly set up decision completed request.</returns> public virtual RespondDecisionTaskCompletedRequest EmptyDecision() { var decisionRequest = new RespondDecisionTaskCompletedRequest { Decisions = new List <Decision>() }; Debug.WriteLine(">>> Decision: <EMPTY>"); return(decisionRequest); }
async Task CompleteTaskAsync(string taskToken, List <Decision> decisions) { RespondDecisionTaskCompletedRequest request = new RespondDecisionTaskCompletedRequest() { Decisions = decisions, TaskToken = taskToken }; await this._swfClient.RespondDecisionTaskCompletedAsync(request); }
public void MakeDecision_UnhandledDecisionTypeTest([Frozen] IDecider decider, [Frozen] RespondDecisionTaskCompletedRequest respondDecisionTask) { _processor = new SDK.Workflow.WorkflowEventsProcessor(_decisionTask, _workflowBase, _pollforDecisionTaskRequest, _amazonSwf); var decisionContext = new WorkflowDecisionContext() { DecisionType = EventType.LambdaFunctionTimedOut }; Assert.Throws <InvalidOperationException>(() => _processor.MakeDecision(decider, decisionContext)); }
/// <summary> /// Starts a timer /// </summary> /// <param name="timerName">Unique name for the timer</param> /// <param name="timeSpan"><The duration of the timer/param> /// <returns></returns> public async Task StartTimerAsync(string timerName, TimeSpan timeSpan) { var workflowContext = await GetCurrentContext(); if (workflowContext != null && workflowContext.Status == Status.STARTED) { var status = GetStatus(Model.ActivityType.Task, timerName, timerName, workflowContext); if (status == Status.NONE) { var decisionRequest = new RespondDecisionTaskCompletedRequest { TaskToken = workflowContext.ReferenceToken, Decisions = new List <Decision> { new Decision { DecisionType = DecisionType.StartTimer, StartTimerDecisionAttributes = new StartTimerDecisionAttributes { TimerId = timerName, StartToFireTimeout = timeSpan.TotalSeconds.ToString() } } } }; await _amazonSimpleWorkflowClient.RespondDecisionTaskCompletedAsync(decisionRequest); } else { await SetMarker(Model.ActivityType.Task, timerName, timerName, status, workflowContext.ReferenceToken); await RaiseEventAsync(Constants.LAMBDA_BIZ_EVENT, _orchestrationId, Constants.LAMBDA_BIZ_EVENT); } if (status == Status.NONE || status == Status.SCHEDULED || status == Status.STARTED) { var waitStatus = Status.NONE; Workflow workflowWaitContext = null; do { workflowWaitContext = await GetCurrentContext(); waitStatus = GetStatus(Model.ActivityType.Timer, timerName, timerName, workflowWaitContext); await SetMarker(Model.ActivityType.Timer, timerName, timerName, waitStatus, workflowWaitContext.ReferenceToken); await RaiseEventAsync(Constants.LAMBDA_BIZ_EVENT, _orchestrationId, Constants.LAMBDA_BIZ_EVENT); } while (waitStatus != Status.SUCCEEDED); } } }
public void MakeDecision_WorkflowExecutionStartedTest([Frozen] IDecider decider, [Frozen] RespondDecisionTaskCompletedRequest respondDecisionTask) { _processor = new SDK.Workflow.WorkflowEventsProcessor(_decisionTask, _workflowBase, _pollforDecisionTaskRequest, _amazonSwf); var decisionContext = new WorkflowDecisionContext() { DecisionType = EventType.WorkflowExecutionStarted }; decider.OnWorkflowExecutionStarted(decisionContext).Returns(info => respondDecisionTask); _decisionCompletedRequest = _processor.MakeDecision(decider, decisionContext); AssertObjectEquals.PropertyValuesAreEqual(_decisionCompletedRequest.Decisions.First(), respondDecisionTask.Decisions.First()); }
public void MakeDecision_NullDeciderTest([Frozen] IDecider decider, [Frozen] RespondDecisionTaskCompletedRequest respondDecisionTask) { _processor = new SDK.Workflow.WorkflowEventsProcessor(_decisionTask, _workflowBase, _pollforDecisionTaskRequest, _amazonSwf); var decisionContext = new WorkflowDecisionContext() { DecisionType = EventType.WorkflowExecutionStarted }; _decisionCompletedRequest = _processor.MakeDecision(null, decisionContext); var decision = _decisionCompletedRequest.Decisions.First(); Assert.NotNull(decision); Assert.Equal(DecisionType.FailWorkflowExecution, decision.DecisionType); Assert.NotNull(decision.FailWorkflowExecutionDecisionAttributes); Assert.Equal("Decider not found.", decision.FailWorkflowExecutionDecisionAttributes.Reason); }
private async Task SetMarker(Model.ActivityType activityType, string name, string id, Status status, string referenceToken) { var decisionRequest = new RespondDecisionTaskCompletedRequest { TaskToken = referenceToken, Decisions = new List <Decision> { new Decision { DecisionType = DecisionType.RecordMarker, RecordMarkerDecisionAttributes = new RecordMarkerDecisionAttributes { MarkerName = Constants.LAMBDA_BIZ_RECORD_MARKER_NAME + "_" + name + "_" + id, Details = activityType.ToString() + "_" + status.ToString() } } } }; await _amazonSimpleWorkflowClient.RespondDecisionTaskCompletedAsync(decisionRequest); }
/// <summary> /// Helper method to create a cancel workflow decision. /// </summary> /// <param name="details">Details for the cancellation.</param> /// <returns>Properly set up decision completed request.</returns> protected RespondDecisionTaskCompletedRequest CancelWorkflow(string details) { var attributes = new CancelWorkflowExecutionDecisionAttributes { Details = details }; var decisionRequest = new RespondDecisionTaskCompletedRequest { Decisions = new List <Decision> { new Decision { DecisionType = "CancelWorkflowExecution", CancelWorkflowExecutionDecisionAttributes = attributes } } }; Debug.WriteLine(">>> Decision: CancelWorkflowExecution"); return(decisionRequest); }
/// <summary> /// Helper method to create a complete workflow decision. /// </summary> /// <param name="result">Result of the activity execution.</param> /// <returns>Properly set up decision completed request.</returns> protected RespondDecisionTaskCompletedRequest CompleteWorkflow(string result) { var attributes = new CompleteWorkflowExecutionDecisionAttributes { Result = result }; var decisionRequest = new RespondDecisionTaskCompletedRequest { Decisions = new List <Decision> { new Decision { DecisionType = "CompleteWorkflowExecution", CompleteWorkflowExecutionDecisionAttributes = attributes } } }; Debug.WriteLine(">>> Decision: CompleteWorkflowExecution"); return(decisionRequest); }
/// <summary> /// Helper method to create a new child workflow decision. /// </summary> /// <param name="workflowContext">Workflow setup context.</param> /// <returns>Properly set up decision completed request.</returns> protected RespondDecisionTaskCompletedRequest StartChildWorkflowExecution(WorkflowSetupContext workflowContext) { var attributes = new StartChildWorkflowExecutionDecisionAttributes { WorkflowId = workflowContext.WorkflowId, WorkflowType = new WorkflowType { Name = workflowContext.WorkflowName, Version = workflowContext.WorkflowVersion }, ChildPolicy = workflowContext.ChildPolicy, Control = workflowContext.Control, ExecutionStartToCloseTimeout = workflowContext.ExecutionStartToCloseTimeout, Input = workflowContext.Input, TagList = workflowContext.TagList, TaskList = new TaskList { Name = workflowContext.TaskList }, TaskStartToCloseTimeout = workflowContext.TaskStartToCloseTimeout, }; var decisionRequest = new RespondDecisionTaskCompletedRequest { Decisions = new List <Decision> { new Decision { DecisionType = "StartChildWorkflowExecution", StartChildWorkflowExecutionDecisionAttributes = attributes } } }; Debug.WriteLine(">>> Decision: StartChildWorkflowExecution" + attributes.WorkflowType.Name + " (" + attributes.WorkflowType.Version + ")"); return(decisionRequest); }
/// <summary> /// Helper method to schedule an activity task /// </summary> /// <param name="activityContext">Activity setup context.</param> /// <returns>Properly set up decision completed request.</returns> protected RespondDecisionTaskCompletedRequest ScheduleActivityTask(WorkflowActivitySetupContext activityContext) { var attributes = new ScheduleActivityTaskDecisionAttributes { ActivityId = activityContext.ActivityId, ActivityType = new ActivityType { Name = activityContext.ActivityName, Version = activityContext.ActivityVersion }, Control = activityContext.Control, HeartbeatTimeout = activityContext.HeartbeatTimeout, Input = activityContext.Input, ScheduleToCloseTimeout = activityContext.ScheduleToCloseTimeout, ScheduleToStartTimeout = activityContext.ScheduleToStartTimeout, StartToCloseTimeout = activityContext.StartToCloseTimeout, TaskList = new TaskList { Name = activityContext.TaskList } }; var decisionRequest = new RespondDecisionTaskCompletedRequest { Decisions = new List <Decision> { new Decision { DecisionType = "ScheduleActivityTask", ScheduleActivityTaskDecisionAttributes = attributes } } }; Debug.WriteLine(">>> Decision: ScheduleActivityTask " + attributes.ActivityType.Name + " (" + attributes.ActivityType.Version + ")"); return(decisionRequest); }
/// <summary> /// Helper method to create a failed workflow decision. /// </summary> /// <param name="details">Failure details.</param> /// <param name="reason">Reason for the failure.</param> /// <returns>Properly set up decision completed request.</returns> protected RespondDecisionTaskCompletedRequest FailWorkflow(string details, string reason) { var attributes = new FailWorkflowExecutionDecisionAttributes { Details = details, Reason = reason }; var decisionRequest = new RespondDecisionTaskCompletedRequest { Decisions = new List <Decision> { new Decision { DecisionType = "FailWorkflowExecution", FailWorkflowExecutionDecisionAttributes = attributes } } }; Debug.WriteLine(">>> Decision: FailWorkflowExecution"); return(decisionRequest); }
/// <summary> /// Helper method to create a record marker decision. /// </summary> /// <param name="details"></param> /// <param name="markerName"></param> /// <returns>Properly set up decision completed request.</returns> protected RespondDecisionTaskCompletedRequest RecordMarker(string details, string markerName) { var attributes = new RecordMarkerDecisionAttributes { Details = details, MarkerName = markerName }; var decisionRequest = new RespondDecisionTaskCompletedRequest { Decisions = new List <Decision> { new Decision { DecisionType = "RecordMarker", RecordMarkerDecisionAttributes = attributes } } }; Debug.WriteLine(">>> Decision: RecordMarker [" + attributes.MarkerName + "] = " + attributes.Details); return(decisionRequest); }
/// <summary> /// Creates an Amazon RespondDecisionTaskCompletedRequest to notify SWF that decison was made based on decision /// </summary> /// <param name="decider"></param> /// <returns></returns> internal RespondDecisionTaskCompletedRequest MakeDecision(IDecider decider, WorkflowDecisionContext decisionContext) { if (decider == null) { var attributes = new FailWorkflowExecutionDecisionAttributes { Details = "WorkflowId: " + decisionContext.WorkflowId, Reason = "Decider not found." }; var decisionRequest = new RespondDecisionTaskCompletedRequest { Decisions = new List <Decision> { new Decision { DecisionType = DecisionType.FailWorkflowExecution, FailWorkflowExecutionDecisionAttributes = attributes } } }; return(decisionRequest); } RespondDecisionTaskCompletedRequest decisionCompletedRequest; // Match the context and call the right method to make a decision if (decisionContext.DecisionType == EventType.WorkflowExecutionStarted) { decisionCompletedRequest = decider.OnWorkflowExecutionStarted(decisionContext); } else if (decisionContext.DecisionType == DecisionType.ContinueAsNewWorkflowExecution) { decisionCompletedRequest = decider.OnWorkflowExecutionContinuedAsNew(decisionContext); } else if (decisionContext.DecisionType == EventType.WorkflowExecutionCancelRequested) { decisionCompletedRequest = decider.OnWorkflowExecutionCancelRequested(decisionContext); } else if (decisionContext.DecisionType == EventType.ActivityTaskCompleted) { decisionCompletedRequest = decider.OnActivityTaskCompleted(decisionContext); } else if (decisionContext.DecisionType == EventType.ActivityTaskFailed) { decisionCompletedRequest = decider.OnActivityTaskFailed(decisionContext); } else if (decisionContext.DecisionType == EventType.ActivityTaskTimedOut) { decisionCompletedRequest = decider.OnActivityTaskTimedOut(decisionContext); } else if (decisionContext.DecisionType == EventType.ScheduleActivityTaskFailed) { decisionCompletedRequest = decider.OnScheduleActivityTaskFailed(decisionContext); } else if (decisionContext.DecisionType == EventType.ChildWorkflowExecutionStarted) { decisionCompletedRequest = decider.OnChildWorkflowExecutionStarted(decisionContext); } else if (decisionContext.DecisionType == EventType.ChildWorkflowExecutionCompleted) { decisionCompletedRequest = decider.OnChildWorkflowExecutionCompleted(decisionContext); } else if (decisionContext.DecisionType == EventType.ChildWorkflowExecutionFailed) { decisionCompletedRequest = decider.OnChildWorkflowExecutionFailed(decisionContext); } else if (decisionContext.DecisionType == EventType.ChildWorkflowExecutionTerminated) { decisionCompletedRequest = decider.OnChildWorkflowExecutionTerminated(decisionContext); } else if (decisionContext.DecisionType == EventType.ChildWorkflowExecutionTimedOut) { decisionCompletedRequest = decider.OnChildWorkflowExecutionTimedOut(decisionContext); } else if (decisionContext.DecisionType == EventType.StartChildWorkflowExecutionFailed) { decisionCompletedRequest = decider.OnStartChildWorkflowExecutionFailed(decisionContext); } else if (decisionContext.DecisionType == EventType.TimerStarted) { decisionCompletedRequest = decider.OnTimerStarted(decisionContext); } else if (decisionContext.DecisionType == EventType.TimerFired) { decisionCompletedRequest = decider.OnTimerFired(decisionContext); } else if (decisionContext.DecisionType == EventType.TimerCanceled) { decisionCompletedRequest = decider.OnTimerCanceled(decisionContext); } else if (decisionContext.DecisionType == EventType.StartChildWorkflowExecutionInitiated) { decisionCompletedRequest = decider.OnStartChildWorkflowExecutionInitiated(decisionContext); } else if (decisionContext.DecisionType == EventType.WorkflowExecutionSignaled) { decisionCompletedRequest = decider.OnWorkflowExecutionSignaled(decisionContext); } else if (decisionContext.DecisionType == EventType.WorkflowExecutionCompleted) { decisionCompletedRequest = decider.OnWorkflowExecutionCompleted(decisionContext); } else { throw new InvalidOperationException("Unhandled event type."); } return(decisionCompletedRequest); }
private async Task <string> CallLambdaAsync(string functionName, object input, string id) { var result = string.Empty; Activity activity = null; var workflowContext = await GetCurrentContext(); if (workflowContext != null && workflowContext.Status == Status.STARTED) { var status = GetStatus(Model.ActivityType.Task, functionName, id, workflowContext); if (status == Status.NONE) { var decisionRequest = new RespondDecisionTaskCompletedRequest { TaskToken = workflowContext.ReferenceToken, Decisions = new List <Decision> { new Decision { DecisionType = DecisionType.ScheduleLambdaFunction, ScheduleLambdaFunctionDecisionAttributes = new ScheduleLambdaFunctionDecisionAttributes { Input = JsonConvert.SerializeObject(input), Name = functionName, Id = id, Control = id } } } }; await _amazonSimpleWorkflowClient.RespondDecisionTaskCompletedAsync(decisionRequest); } else { await SetMarker(Model.ActivityType.Task, functionName, id, status, workflowContext.ReferenceToken); await RaiseEventAsync(Constants.LAMBDA_BIZ_EVENT, _orchestrationId, Constants.LAMBDA_BIZ_EVENT); activity = FindActivity(Model.ActivityType.Task, id, functionName, workflowContext.Activities); } if (status == Status.NONE || status == Status.SCHEDULED || status == Status.STARTED) { var waitStatus = Status.NONE; Workflow workflowWaitContext = null; do { workflowWaitContext = await GetCurrentContext(); waitStatus = GetStatus(Model.ActivityType.Task, functionName, id, workflowWaitContext); await SetMarker(Model.ActivityType.Task, functionName, id, waitStatus, workflowWaitContext.ReferenceToken); await RaiseEventAsync(Constants.LAMBDA_BIZ_EVENT, _orchestrationId, Constants.LAMBDA_BIZ_EVENT); }while (waitStatus != Status.SUCCEEDED && waitStatus != Status.FAILED && waitStatus != Status.TIMEOUT); activity = FindActivity(Model.ActivityType.Task, id, functionName, workflowWaitContext.Activities); } } if (activity.Status == Status.FAILED) { throw new Exception(activity.FailureDetails); } if (activity.Status == Status.TIMEOUT) { throw new Exception("Time-Out"); } result = activity.Result; return(result); }
private async Task <string> CallServiceAsync(string url, string method, string queryString, object input, Dictionary <string, string> headers, string id) { var result = string.Empty; Activity activity = null; var restConfig = new RESTConfig { Body = input == null ? null: JsonConvert.SerializeObject(input), Headers = headers, Method = method, QueryString = queryString, Url = url }; var workflowContext = await GetCurrentContext(); if (workflowContext != null && workflowContext.Status == Status.STARTED) { var status = GetStatus(Model.ActivityType.Task, Constants.LAMBDA_BIZ_ACTIVITY_TYPE, id, workflowContext); if (status == Status.NONE) { var decisionRequest = new RespondDecisionTaskCompletedRequest { TaskToken = workflowContext.ReferenceToken, Decisions = new List <Decision> { new Decision { DecisionType = DecisionType.ScheduleActivityTask, ScheduleActivityTaskDecisionAttributes = new ScheduleActivityTaskDecisionAttributes { Input = JsonConvert.SerializeObject(restConfig), ActivityId = id, Control = id, ActivityType = new Amazon.SimpleWorkflow.Model.ActivityType { Name = Constants.LAMBDA_BIZ_ACTIVITY_TYPE, Version = Constants.LAMBDA_BIZ_TYPE_VERSION }, TaskList = new TaskList { Name = Constants.LAMBDA_BIZ_TASK_LIST + _orchestrationId }, StartToCloseTimeout = "NONE", ScheduleToCloseTimeout = "NONE", ScheduleToStartTimeout = "NONE", HeartbeatTimeout = "NONE" }, } } }; await _amazonSimpleWorkflowClient.RespondDecisionTaskCompletedAsync(decisionRequest); } else { await SetMarker(Model.ActivityType.Task, Constants.LAMBDA_BIZ_ACTIVITY_TYPE, id, status, workflowContext.ReferenceToken); await RaiseEventAsync(Constants.LAMBDA_BIZ_EVENT, _orchestrationId, Constants.LAMBDA_BIZ_EVENT); activity = FindActivity(Model.ActivityType.Task, id, Constants.LAMBDA_BIZ_ACTIVITY_TYPE, workflowContext.Activities); } if (status == Status.NONE || status == Status.SCHEDULED || status == Status.STARTED) { var waitStatus = Status.NONE; Workflow workflowWaitContext = null; do { workflowWaitContext = await GetCurrentContext(); waitStatus = GetStatus(Model.ActivityType.Task, Constants.LAMBDA_BIZ_ACTIVITY_TYPE, id, workflowWaitContext); await SetMarker(Model.ActivityType.Task, Constants.LAMBDA_BIZ_ACTIVITY_TYPE, id, waitStatus, workflowWaitContext.ReferenceToken); await RaiseEventAsync(Constants.LAMBDA_BIZ_EVENT, _orchestrationId, Constants.LAMBDA_BIZ_EVENT); }while (waitStatus != Status.SUCCEEDED && waitStatus != Status.FAILED && waitStatus != Status.TIMEOUT); activity = FindActivity(Model.ActivityType.Task, id, Constants.LAMBDA_BIZ_ACTIVITY_TYPE, workflowWaitContext.Activities); } } if (activity.Status == Status.FAILED) { throw new Exception(activity.FailureDetails); } if (activity.Status == Status.TIMEOUT) { throw new Exception("Time-Out"); } result = activity.Result; return(result); }
public void Decider() { int activityCount = 0; while (true) { Console.WriteLine("Decider: Polling for decision task ..."); PollForDecisionTaskRequest request = new PollForDecisionTaskRequest() { Domain = domainName, TaskList = new TaskList() { Name = deciderPollingKey } }; PollForDecisionTaskResponse response = swfClient.PollForDecisionTaskAsync(request).Result; if (response.DecisionTask.TaskToken == null) { Console.WriteLine("Decider: NULL"); continue; } int completedActivityTaskCount = 0, totalActivityTaskCount = 0; foreach (HistoryEvent e in response.DecisionTask.Events) { Console.WriteLine("Decider: EventType - " + e.EventType + ", EventId - " + e.EventId); if (e.EventType == "ActivityTaskCompleted") { completedActivityTaskCount++; } if (e.EventType.Value.StartsWith("Activity")) { totalActivityTaskCount++; } } Console.WriteLine(".... completedCount=" + completedActivityTaskCount); List <Decision> decisions = new List <Decision>(); if (totalActivityTaskCount == 0) { ScheduleActivity("Activity1", decisions); activityCount = 4; } else if (completedActivityTaskCount == activityCount) { Decision decision = new Decision() { DecisionType = DecisionType.CompleteWorkflowExecution, CompleteWorkflowExecutionDecisionAttributes = new CompleteWorkflowExecutionDecisionAttributes { Result = "{\"Result\":\"WF Complete!\"}" } }; decisions.Add(decision); Console.WriteLine("Worflow Complete"); } RespondDecisionTaskCompletedRequest respondDecisionTaskCompletedRequest = new RespondDecisionTaskCompletedRequest() { Decisions = decisions, TaskToken = response.DecisionTask.TaskToken }; swfClient.RespondDecisionTaskCompletedAsync(respondDecisionTaskCompletedRequest); } }
public void TestPollDecider() { string workflowId = DateTime.Now.Ticks.ToString(); var startRequest = new StartWorkflowExecutionRequest() { Domain = DOMAIN, WorkflowId = workflowId, ChildPolicy = "TERMINATE", TaskList = TASKLIST, Input = "ImportantKeyId", WorkflowType = WORKFLOW_TYPE }; var startResponse = Client.StartWorkflowExecution(startRequest); var pollDeciderRequest = new PollForDecisionTaskRequest() { Domain = DOMAIN, TaskList = TASKLIST, Identity = "testdecider" }; var pollDeciderResponse = Client.PollForDecisionTask(pollDeciderRequest); Assert.IsNotNull(pollDeciderResponse.DecisionTask); Assert.IsTrue(pollDeciderResponse.DecisionTask.Events.Count > 0); Assert.IsNotNull(pollDeciderResponse.DecisionTask.Events[0].EventId); Assert.IsNotNull(pollDeciderResponse.DecisionTask.Events[0].EventType); Assert.AreEqual(DateTime.Today, pollDeciderResponse.DecisionTask.Events[0].EventTimestamp.ToLocalTime().Date); var task = pollDeciderResponse.DecisionTask; var respondRequest = new RespondDecisionTaskCompletedRequest() { TaskToken = task.TaskToken, Decisions = new List <Decision>() { new Decision() { DecisionType = "ScheduleActivityTask", ScheduleActivityTaskDecisionAttributes = new ScheduleActivityTaskDecisionAttributes() { ActivityType = ACTIVITY_TYPE, ActivityId = DateTime.Now.Ticks.ToString(), TaskList = TASKLIST } } } }; Client.RespondDecisionTaskCompleted(respondRequest); var pollActivityRequest = new PollForActivityTaskRequest() { Domain = DOMAIN, TaskList = TASKLIST, Identity = "testactivity" }; var pollActivityResponse = Client.PollForActivityTask(pollActivityRequest); Assert.IsNotNull(pollActivityResponse.ResponseMetadata.RequestId); Assert.AreEqual(ACTIVITY_TYPE.Name, pollActivityResponse.ActivityTask.ActivityType.Name); Assert.AreEqual(ACTIVITY_TYPE.Version, pollActivityResponse.ActivityTask.ActivityType.Version); var signalRequest = new SignalWorkflowExecutionRequest() { Domain = DOMAIN, RunId = startResponse.Run.RunId, WorkflowId = startRequest.WorkflowId, SignalName = "TestSignal" }; var signalResponse = Client.SignalWorkflowExecution(signalRequest); Assert.IsNotNull(signalResponse.ResponseMetadata.RequestId); }
// Simple logic // Creates four activities at the begining // Waits for them to complete and completes the workflow static void Decider() { int activityCount = 0; // This refers to total number of activities per workflow IAmazonSimpleWorkflow swfClient = AWSClientFactory.CreateAmazonSimpleWorkflowClient(); while (true) { Console.WriteLine("Decider: Polling for decision task ..."); PollForDecisionTaskRequest request = new PollForDecisionTaskRequest() { Domain = domainName, TaskList = new TaskList() { Name = "HelloWorld" } }; PollForDecisionTaskResponse response = swfClient.PollForDecisionTask(request); if (response.DecisionTask.TaskToken == null) { Console.WriteLine("Decider: NULL"); continue; } int completedActivityTaskCount = 0, totalActivityTaskCount = 0; foreach (HistoryEvent e in response.DecisionTask.Events) { Console.WriteLine("Decider: EventType - " + e.EventType + ", EventId - " + e.EventId); if (e.EventType == "ActivityTaskCompleted") { completedActivityTaskCount++; } if (e.EventType.Value.StartsWith("Activity")) { totalActivityTaskCount++; } } Console.WriteLine(".... completedCount=" + completedActivityTaskCount); List <Decision> decisions = new List <Decision>(); if (totalActivityTaskCount == 0) // Create this only at the begining { ScheduleActivity("Activity1A", decisions); ScheduleActivity("Activity1B", decisions); ScheduleActivity("Activity2", decisions); ScheduleActivity("Activity2", decisions); activityCount = 4; } else if (completedActivityTaskCount == activityCount) { Decision decision = new Decision() { DecisionType = DecisionType.CompleteWorkflowExecution, CompleteWorkflowExecutionDecisionAttributes = new CompleteWorkflowExecutionDecisionAttributes { Result = "{\"Result\":\"WF Complete!\"}" } }; decisions.Add(decision); Console.WriteLine("Decider: WORKFLOW COMPLETE!!!!!!!!!!!!!!!!!!!!!!"); } RespondDecisionTaskCompletedRequest respondDecisionTaskCompletedRequest = new RespondDecisionTaskCompletedRequest() { Decisions = decisions, TaskToken = response.DecisionTask.TaskToken }; swfClient.RespondDecisionTaskCompleted(respondDecisionTaskCompletedRequest); } }
// Simple logic // Creates four activities at the begining // Waits for them to complete and completes the workflow static void Decider() { int activityCount = 0; // This refers to total number of activities per workflow while (true) { Console.WriteLine("DECIDER: Polling for decision task ..."); var request = new PollForDecisionTaskRequest() { Domain = domainName, TaskList = new TaskList() { Name = "SwfDemo" } }; var response = SwfDeciderClient.PollForDecisionTask(request); if (response.DecisionTask.TaskToken == null) { Console.WriteLine("DECIDER: NULL"); continue; } int completedActivityTaskCount = 0, totalActivityTaskCount = 0; foreach (HistoryEvent e in response.DecisionTask.Events) { Console.WriteLine($"DECIDER: EventType - {e.EventType}" + $", EventId - {e.EventId}"); if (e.EventType == "ActivityTaskCompleted") { completedActivityTaskCount++; } if (e.EventType.Value.StartsWith("Activity")) { totalActivityTaskCount++; } } Console.WriteLine($"completedCount={completedActivityTaskCount}"); var decisions = new List <Decision>(); if (totalActivityTaskCount == 0) // Create this only at the begining { ScheduleActivity("Activity1A", decisions); ScheduleActivity("Activity1B", decisions); ScheduleActivity("Activity2", decisions); ScheduleActivity("Activity2", decisions); activityCount = 4; } else if (completedActivityTaskCount == activityCount) { var decision = new Decision() { DecisionType = DecisionType.CompleteWorkflowExecution, CompleteWorkflowExecutionDecisionAttributes = new CompleteWorkflowExecutionDecisionAttributes { Result = "{\"Result\":\"WF Complete!\"}" } }; decisions.Add(decision); Console.WriteLine("DECIDER: WORKFLOW COMPLETE"); } var respondDecisionTaskCompletedRequest = new RespondDecisionTaskCompletedRequest() { Decisions = decisions, TaskToken = response.DecisionTask.TaskToken }; SwfDeciderClient.RespondDecisionTaskCompleted(respondDecisionTaskCompletedRequest); } }