Esempio n. 1
0
        /// <summary>
        /// Retrieves the next page of history from SWF.
        /// </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.PollForDecisionTask(request).DecisionTask;
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine("Poll request failed with exception: " + ex);
                    pollFailed = true;
                }

                currentTry += 1;
            } while (pollFailed && currentTry <= retryCount);

            return(_lastResponse.Events);
        }
        IEnumerable <PollForDecisionTaskResponse> IPaginator <PollForDecisionTaskResponse> .Paginate()
        {
            if (Interlocked.Exchange(ref _isPaginatorInUse, 1) != 0)
            {
                throw new System.InvalidOperationException("Paginator has already been consumed and cannot be reused. Please create a new instance.");
            }
            var nextPageToken = _request.NextPageToken;
            PollForDecisionTaskResponse response;

            do
            {
                _request.NextPageToken = nextPageToken;
                response      = _client.PollForDecisionTask(_request);
                nextPageToken = response.DecisionTask.NextPageToken;
                yield return(response);
            }while (nextPageToken != null);
        }
Esempio n. 3
0
File: Program.cs Progetto: wse/AWS
        // 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);
            }
        }
Esempio n. 4
0
        // 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);
            }
        }