Exemple #1
0
        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);

            WorkflowExecutionInfos resp = new WorkflowExecutionInfos();

            do
            {
                ListOpenWorkflowExecutionsRequest req = new ListOpenWorkflowExecutionsRequest
                {
                    NextPageToken = resp.NextPageToken
                    ,
                    MaximumPageSize = maxItems
                };

                resp = client.ListOpenWorkflowExecutions(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.ExecutionInfos)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextPageToken));
        }
        public void StartAndTerminateWorkflowExecution()
        {
            string domainName = "sdk-dotnet-start-" + DateTime.Now.Ticks;
            var    regRequest = new RegisterDomainRequest()
            {
                Name        = domainName,
                Description = "A Description",
                WorkflowExecutionRetentionPeriodInDays = "4"
            };

            Client.RegisterDomain(regRequest);
            try
            {
                var regWorkflowRequest = new RegisterWorkflowTypeRequest()
                {
                    Name        = "Start and Terminate Workflow",
                    Domain      = domainName,
                    Description = "Another Description",
                    Version     = "1.0",
                    DefaultExecutionStartToCloseTimeout = FIVE_HOUR_DURATION,
                    DefaultTaskStartToCloseTimeout      = FOUR_HOUR_DURATION
                };

                var regWorkflowResponse = Client.RegisterWorkflowType(regWorkflowRequest);
                try
                {
                    Sleep(); // Sleep for the eventual consistency
                    var workflowId   = DateTime.Now.Ticks.ToString();
                    var startRequest = new StartWorkflowExecutionRequest()
                    {
                        Domain      = domainName,
                        WorkflowId  = workflowId,
                        ChildPolicy = "TERMINATE",
                        TaskList    = new TaskList()
                        {
                            Name = "ImportantTasks"
                        },
                        WorkflowType = new WorkflowType()
                        {
                            Name = regWorkflowRequest.Name, Version = regWorkflowRequest.Version
                        }
                    };

                    var startResponse = Client.StartWorkflowExecution(startRequest);
                    Assert.IsNotNull(startResponse.Run.RunId);

                    Thread.Sleep(10 * 1000);
                    var countWorkRequest = new CountOpenWorkflowExecutionsRequest()
                    {
                        Domain          = domainName,
                        StartTimeFilter = new ExecutionTimeFilter()
                        {
                            OldestDate = DateTime.Now.AddDays(-4),
                            LatestDate = DateTime.Now.AddDays(1)
                        },
                        ExecutionFilter = new WorkflowExecutionFilter()
                        {
                            WorkflowId = workflowId
                        }
                    };

                    var countWorkResponse = Client.CountOpenWorkflowExecutions(countWorkRequest);

                    Assert.AreEqual(1, countWorkResponse.WorkflowExecutionCount.Count);

                    var listWorkRequest = new ListOpenWorkflowExecutionsRequest()
                    {
                        Domain          = domainName,
                        StartTimeFilter = new ExecutionTimeFilter()
                        {
                            OldestDate = DateTime.Now.AddDays(-4),
                            LatestDate = DateTime.Now.AddDays(1)
                        },
                        ExecutionFilter = new WorkflowExecutionFilter()
                        {
                            WorkflowId = workflowId
                        }
                    };

                    var listWorkResponse = Client.ListOpenWorkflowExecutions(listWorkRequest);
                    Assert.AreEqual(1, listWorkResponse.WorkflowExecutionInfos.ExecutionInfos.Count);

                    var info = listWorkResponse.WorkflowExecutionInfos.ExecutionInfos[0];
                    Assert.AreEqual(regWorkflowRequest.Name, info.WorkflowType.Name);
                    Assert.AreEqual(regWorkflowRequest.Version, info.WorkflowType.Version);
                    Assert.AreEqual(startResponse.Run.RunId, info.Execution.RunId);
                    Assert.AreEqual(startRequest.WorkflowId, info.Execution.WorkflowId);

                    var descRequest = new DescribeWorkflowExecutionRequest()
                    {
                        Domain    = domainName,
                        Execution = new WorkflowExecution()
                        {
                            RunId      = startResponse.Run.RunId,
                            WorkflowId = startRequest.WorkflowId
                        }
                    };

                    var descResponse = Client.DescribeWorkflowExecution(descRequest);

                    Assert.IsNotNull(descResponse.WorkflowExecutionDetail);
                    Assert.AreEqual(startRequest.TaskList.Name, descResponse.WorkflowExecutionDetail.ExecutionConfiguration.TaskList.Name);

                    var termRequest = new TerminateWorkflowExecutionRequest()
                    {
                        Domain      = domainName,
                        ChildPolicy = "TERMINATE",
                        WorkflowId  = workflowId
                    };

                    var termResponse = Client.TerminateWorkflowExecution(termRequest);
                    Assert.IsNotNull(termResponse.ResponseMetadata.RequestId);
                }
                finally
                {
                    Client.DeprecateWorkflowType(new DeprecateWorkflowTypeRequest()
                    {
                        Domain       = domainName,
                        WorkflowType = new WorkflowType()
                        {
                            Name    = "Start and Terminate Workflow",
                            Version = "1.0"
                        }
                    });
                }
            }
            finally
            {
                var depRequest = new DeprecateDomainRequest()
                {
                    Name = domainName
                };
                Client.DeprecateDomain(depRequest);
            }
        }