/// <summary> /// The method tells SWF what decisions have been made for the current decision task. /// </summary> /// <param name="taskToken"></param> /// <param name="decisions"></param> void CompleteTask(string taskToken, List<Decision> decisions) { RespondDecisionTaskCompletedRequest request = new RespondDecisionTaskCompletedRequest() { Decisions = decisions, TaskToken = taskToken }; this._swfClient.RespondDecisionTaskCompleted(request); }
async Task CompleteTaskAsync(string taskToken, List<Decision> decisions) { RespondDecisionTaskCompletedRequest request = new RespondDecisionTaskCompletedRequest() { Decisions = decisions, TaskToken = taskToken }; await this._swfClient.RespondDecisionTaskCompletedAsync(request); }
/// <summary> /// Used by deciders to tell the service that the <a>DecisionTask</a> identified by the /// <code>taskToken</code> has successfully completed. The <code>decisions</code> argument /// specifies the list of decisions made while processing the task. /// /// /// <para> /// A <code>DecisionTaskCompleted</code> event is added to the workflow history. The /// <code>executionContext</code> specified is attached to the event in the workflow execution /// history. /// </para> /// /// <para> /// <b>Access Control</b> /// </para> /// /// <para> /// If an IAM policy grants permission to use <code>RespondDecisionTaskCompleted</code>, /// it can express permissions for the list of decisions in the <code>decisions</code> /// parameter. Each of the decisions has one or more parameters, much like a regular API /// call. To allow for policies to be as readable as possible, you can express permissions /// on decisions as if they were actual API calls, including applying conditions to some /// parameters. For more information, see <a href="http://docs.aws.amazon.com/amazonswf/latest/developerguide/swf-dev-iam.html">Using /// IAM to Manage Access to Amazon SWF Workflows</a>. /// </para> /// </summary> /// <param name="request">Container for the necessary parameters to execute the RespondDecisionTaskCompleted service method.</param> /// /// <returns>The response from the RespondDecisionTaskCompleted service method, as returned by SimpleWorkflow.</returns> /// <exception cref="OperationNotPermittedException"> /// Returned when the caller does not have sufficient permissions to invoke the action. /// </exception> /// <exception cref="UnknownResourceException"> /// Returned when the named resource cannot be found with in the scope of this operation /// (region or domain). This could happen if the named resource was never created or is /// no longer available for this operation. /// </exception> public RespondDecisionTaskCompletedResponse RespondDecisionTaskCompleted(RespondDecisionTaskCompletedRequest request) { var marshaller = new RespondDecisionTaskCompletedRequestMarshaller(); var unmarshaller = RespondDecisionTaskCompletedResponseUnmarshaller.Instance; return Invoke<RespondDecisionTaskCompletedRequest,RespondDecisionTaskCompletedResponse>(request, marshaller, unmarshaller); }
/// <summary> /// Initiates the asynchronous execution of the RespondDecisionTaskCompleted operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the RespondDecisionTaskCompleted operation on AmazonSimpleWorkflowClient.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> /// /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndRespondDecisionTaskCompleted /// operation.</returns> public IAsyncResult BeginRespondDecisionTaskCompleted(RespondDecisionTaskCompletedRequest request, AsyncCallback callback, object state) { var marshaller = new RespondDecisionTaskCompletedRequestMarshaller(); var unmarshaller = RespondDecisionTaskCompletedResponseUnmarshaller.Instance; return BeginInvoke<RespondDecisionTaskCompletedRequest>(request, marshaller, unmarshaller, callback, state); }
/// <summary> /// <para> Used by deciders to tell the service that the DecisionTask identified by the <c>taskToken</c> has successfully completed. The /// <c>decisions</c> argument specifies the list of decisions made while processing the task. </para> <para> A /// <c>DecisionTaskCompleted</c> event is added to the workflow history. The <c>executionContext</c> specified is attached /// to the event in the workflow execution history. </para> <para> <b>Access Control</b> </para> <para>If an IAM policy grants permission to use /// <c>RespondDecisionTaskCompleted</c> , it can express permissions for the list of decisions in the <c>decisions</c> parameter. Each of the /// decisions has one or more parameters, much like a regular API call. To allow for policies to be as readable as possible, you can express /// permissions on decisions as if they were actual API calls, including applying conditions to some parameters. For more information, see <a href="http://docs.aws.amazon.com/amazonswf/latest/developerguide/swf-dev-iam.html">Using IAM to Manage Access to Amazon SWF Workflows</a> /// .</para> /// </summary> /// /// <param name="respondDecisionTaskCompletedRequest">Container for the necessary parameters to execute the RespondDecisionTaskCompleted service /// method on AmazonSimpleWorkflow.</param> /// /// <exception cref="T:Amazon.SimpleWorkflow.Model.OperationNotPermittedException" /> /// <exception cref="T:Amazon.SimpleWorkflow.Model.UnknownResourceException" /> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> public async Task<RespondDecisionTaskCompletedResponse> RespondDecisionTaskCompletedAsync(RespondDecisionTaskCompletedRequest respondDecisionTaskCompletedRequest, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new RespondDecisionTaskCompletedRequestMarshaller(); var unmarshaller = RespondDecisionTaskCompletedResponseUnmarshaller.GetInstance(); var response = await Invoke<IRequest, RespondDecisionTaskCompletedRequest, RespondDecisionTaskCompletedResponse>(respondDecisionTaskCompletedRequest, marshaller, unmarshaller, signer, cancellationToken) .ConfigureAwait(continueOnCapturedContext: false); return response; }
internal RespondDecisionTaskCompletedResponse RespondDecisionTaskCompleted(RespondDecisionTaskCompletedRequest request) { var task = RespondDecisionTaskCompletedAsync(request); try { return task.Result; } catch(AggregateException e) { throw e.InnerException; } }
/// <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; }
IAsyncResult invokeRespondDecisionTaskCompleted(RespondDecisionTaskCompletedRequest respondDecisionTaskCompletedRequest, AsyncCallback callback, object state, bool synchronized) { IRequest irequest = new RespondDecisionTaskCompletedRequestMarshaller().Marshall(respondDecisionTaskCompletedRequest); var unmarshaller = RespondDecisionTaskCompletedResponseUnmarshaller.GetInstance(); AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller); Invoke(result); return result; }
/// <summary> /// <para> Used by deciders to tell the service that the DecisionTask identified by the <c>taskToken</c> has successfully completed. The /// <c>decisions</c> argument specifies the list of decisions made while processing the task. </para> <para> A /// <c>DecisionTaskCompleted</c> event is added to the workflow history. The <c>executionContext</c> specified is attached /// to the event in the workflow execution history. </para> <para> <b>Access Control</b> </para> <para>If an IAM policy grants permission to use /// <c>RespondDecisionTaskCompleted</c> , it can express permissions for the list of decisions in the <c>decisions</c> parameter. Each of the /// decisions has one or more parameters, much like a regular API call. To allow for policies to be as readable as possible, you can express /// permissions on decisions as if they were actual API calls, including applying conditions to some parameters. For more information, see <a href="http://docs.aws.amazon.com/amazonswf/latest/developerguide/swf-dev-iam.html">Using IAM to Manage Access to Amazon SWF Workflows</a> /// .</para> /// </summary> /// /// <param name="respondDecisionTaskCompletedRequest">Container for the necessary parameters to execute the RespondDecisionTaskCompleted service /// method on AmazonSimpleWorkflow.</param> /// /// <exception cref="T:Amazon.SimpleWorkflow.Model.OperationNotPermittedException" /> /// <exception cref="T:Amazon.SimpleWorkflow.Model.UnknownResourceException" /> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> public Task<RespondDecisionTaskCompletedResponse> RespondDecisionTaskCompletedAsync(RespondDecisionTaskCompletedRequest respondDecisionTaskCompletedRequest, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new RespondDecisionTaskCompletedRequestMarshaller(); var unmarshaller = RespondDecisionTaskCompletedResponseUnmarshaller.GetInstance(); return Invoke<IRequest, RespondDecisionTaskCompletedRequest, RespondDecisionTaskCompletedResponse>(respondDecisionTaskCompletedRequest, marshaller, unmarshaller, signer, cancellationToken); }
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> /// 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> /// 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 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> /// Initiates the asynchronous execution of the RespondDecisionTaskCompleted operation. /// <seealso cref="Amazon.SimpleWorkflow.IAmazonSimpleWorkflow"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the RespondDecisionTaskCompleted operation.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns>The task object representing the asynchronous operation.</returns> public Task<RespondDecisionTaskCompletedResponse> RespondDecisionTaskCompletedAsync(RespondDecisionTaskCompletedRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new RespondDecisionTaskCompletedRequestMarshaller(); var unmarshaller = RespondDecisionTaskCompletedResponseUnmarshaller.Instance; return InvokeAsync<RespondDecisionTaskCompletedRequest,RespondDecisionTaskCompletedResponse>(request, marshaller, unmarshaller, cancellationToken); }
internal RespondDecisionTaskCompletedResponse RespondDecisionTaskCompleted(RespondDecisionTaskCompletedRequest request) { var task = RespondDecisionTaskCompletedAsync(request); try { return task.Result; } catch(AggregateException e) { ExceptionDispatchInfo.Capture(e.InnerException).Throw(); return null; } }
/// <summary> /// <para> Used by deciders to tell the service that the DecisionTask identified by the <c>taskToken</c> has successfully completed. The /// <c>decisions</c> argument specifies the list of decisions made while processing the task. </para> <para> A /// <c>DecisionTaskCompleted</c> event is added to the workflow history. The <c>executionContext</c> specified is attached /// to the event in the workflow execution history. </para> /// </summary> /// /// <param name="respondDecisionTaskCompletedRequest">Container for the necessary parameters to execute the RespondDecisionTaskCompleted service /// method on AmazonSimpleWorkflow.</param> /// /// <exception cref="OperationNotPermittedException"/> /// <exception cref="UnknownResourceException"/> public RespondDecisionTaskCompletedResponse RespondDecisionTaskCompleted(RespondDecisionTaskCompletedRequest respondDecisionTaskCompletedRequest) { IRequest<RespondDecisionTaskCompletedRequest> request = new RespondDecisionTaskCompletedRequestMarshaller().Marshall(respondDecisionTaskCompletedRequest); RespondDecisionTaskCompletedResponse response = Invoke<RespondDecisionTaskCompletedRequest, RespondDecisionTaskCompletedResponse> (request, this.signer, RespondDecisionTaskCompletedResponseUnmarshaller.GetInstance()); return response; }
/// <summary> /// <para> Used by deciders to tell the service that the DecisionTask identified by the <c>taskToken</c> has successfully completed. The /// <c>decisions</c> argument specifies the list of decisions made while processing the task. </para> <para> A /// <c>DecisionTaskCompleted</c> event is added to the workflow history. The <c>executionContext</c> specified is attached /// to the event in the workflow execution history. </para> /// </summary> /// /// <param name="respondDecisionTaskCompletedRequest">Container for the necessary parameters to execute the RespondDecisionTaskCompleted service /// method on AmazonSimpleWorkflow.</param> /// /// <exception cref="OperationNotPermittedException"/> /// <exception cref="UnknownResourceException"/> public RespondDecisionTaskCompletedResponse RespondDecisionTaskCompleted(RespondDecisionTaskCompletedRequest respondDecisionTaskCompletedRequest) { IAsyncResult asyncResult = invokeRespondDecisionTaskCompleted(respondDecisionTaskCompletedRequest, null, null, true); return EndRespondDecisionTaskCompleted(asyncResult); }
// 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); } }
/// <summary> /// Initiates the asynchronous execution of the RespondDecisionTaskCompleted operation. /// <seealso cref="Amazon.SimpleWorkflow.AmazonSimpleWorkflow.RespondDecisionTaskCompleted"/> /// </summary> /// /// <param name="respondDecisionTaskCompletedRequest">Container for the necessary parameters to execute the RespondDecisionTaskCompleted /// operation on AmazonSimpleWorkflow.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> public IAsyncResult BeginRespondDecisionTaskCompleted(RespondDecisionTaskCompletedRequest respondDecisionTaskCompletedRequest, AsyncCallback callback, object state) { return invokeRespondDecisionTaskCompleted(respondDecisionTaskCompletedRequest, callback, state, false); }
/// <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; }