/// <summary> /// Registers activity type for a specific version. /// </summary> /// <param name="domainName">Domain where the activity type should be registered.</param> /// <param name="client">Interface for accessing Amazon Simple Workflow Service.</param> void IRegistrable.Register(string domainName, IAmazonSimpleWorkflow client) { var listActivityRequest = new ListActivityTypesRequest { Domain = domainName, Name = Options.Name, RegistrationStatus = RegistrationStatus.REGISTERED }; if ( client.ListActivityTypesAsync(listActivityRequest).Result .ActivityTypeInfos.TypeInfos.FirstOrDefault(x => x.ActivityType.Version == Options.Version) == null) { Logger.Trace("New Activity Type."); RegisterActivityTypeRequest request = new RegisterActivityTypeRequest { Name = Options.Name, Domain = domainName, Description = Options.Description, Version = Options.Version, DefaultTaskList = TaskList, //Worker poll based on this DefaultTaskScheduleToCloseTimeout = Options.ScheduleToCloseTimeout.ToStringOrNone(), DefaultTaskScheduleToStartTimeout = Options.ScheduleToStartTimeout.ToStringOrNone(), DefaultTaskStartToCloseTimeout = Options.StartToCloseTimeout.ToStringOrNone(), DefaultTaskHeartbeatTimeout = Options.HeartbeatTimeout.ToStringOrNone() }; client.RegisterActivityTypeAsync(request).Wait(); } Logger.Trace("Activity. Name: {0}, Version: {1}", Options.Name, Options.Version); }
public static void RegisterActivity(IAmazonSimpleWorkflow swfClient, string domainName, string name, string tasklistName) { // Register activities if it is not already registered var listActivityRequest = new ListActivityTypesRequest() { Domain = domainName, Name = name, RegistrationStatus = RegistrationStatus.REGISTERED }; if (swfClient.ListActivityTypes(listActivityRequest).ActivityTypeInfos.TypeInfos.FirstOrDefault( x => x.ActivityType.Version == "2.0") == null) { RegisterActivityTypeRequest request = new RegisterActivityTypeRequest() { Name = name, Domain = domainName, Description = "Hello World Activities", Version = "2.0", DefaultTaskList = new TaskList() { Name = tasklistName }, //Worker poll based on this DefaultTaskScheduleToCloseTimeout = "300", DefaultTaskScheduleToStartTimeout = "150", DefaultTaskStartToCloseTimeout = "450", DefaultTaskHeartbeatTimeout = "NONE", }; swfClient.RegisterActivityType(request); Console.WriteLine("Setup: Created Activity Name - " + request.Name); } }
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 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 }; }
public static void RegisterWorkflow(IAmazonSimpleWorkflow swfClient, string name, string domainName) { // Register workflow type if not already registered var listWorkflowRequest = new ListWorkflowTypesRequest() { Name = name, Domain = domainName, RegistrationStatus = RegistrationStatus.REGISTERED }; if (swfClient.ListWorkflowTypes(listWorkflowRequest).WorkflowTypeInfos.TypeInfos.FirstOrDefault( x => x.WorkflowType.Version == "2.0") == null) { RegisterWorkflowTypeRequest request = new RegisterWorkflowTypeRequest() { DefaultChildPolicy = ChildPolicy.TERMINATE, DefaultExecutionStartToCloseTimeout = "300", DefaultTaskList = new TaskList() { Name = "HelloWorld" // Decider need to poll for this task }, DefaultTaskStartToCloseTimeout = "150", Domain = domainName, Name = name, Version = "2.0" }; swfClient.RegisterWorkflowType(request); Console.WriteLine("Setup: Registerd Workflow Name - " + request.Name); } }
/// <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); }
/// <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); }
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 async Task SendAsync(IAmazonSimpleWorkflow simpleWorkflow, CancellationToken cancellationToken) { var request = new RespondActivityTaskCanceledRequest() { TaskToken = _taskToken, Details = _details }; await simpleWorkflow.RespondActivityTaskCanceledAsync(request, cancellationToken); }
public override async Task SendAsync(IAmazonSimpleWorkflow simpleWorkflow, CancellationToken cancellationToken) { var request = new RespondActivityTaskCompletedRequest() { Result = _result, TaskToken = _taskToken }; await simpleWorkflow.RespondActivityTaskCompletedAsync(request, cancellationToken); }
private Domain(string name, IAmazonSimpleWorkflow simpleWorkflowClient, IErrorHandler errorHandler) { Ensure.NotNullAndEmpty(name, () => new ArgumentException(Resources.Domain_name_required, nameof(name))); Ensure.NotNull(simpleWorkflowClient, "simpleWorkflowClient"); _name = name; _simpleWorkflowClient = simpleWorkflowClient; _errorHandler = errorHandler; }
/// <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; }
public ActivityWorker(string domain, string taskList, IAmazonSimpleWorkflow swfClient) { Debug.Assert(swfClient != null); _Domain = domain; _TaskList = taskList; _swfClient = swfClient; }
PollWriterManager() { this._snsClient = new AmazonSimpleNotificationServiceClient(); this._dynamoDBClient = new AmazonDynamoDBClient(); this._dbContext = new DynamoDBContext(this._dynamoDBClient, new DynamoDBContextConfig { Conversion = DynamoDBEntryConversion.V2 }); this._swfClient = new AmazonSimpleWorkflowClient(); }
public ActivityWorker(IWorkflow workflow, IAmazonSimpleWorkflow swfClient) { Debug.Assert(workflow != null); Debug.Assert(swfClient != null); _Domain = workflow.Options.Domain; _TaskList = workflow.TaskList.Name; _workflow = workflow; _swfClient = swfClient; }
internal override async Task SendAsync(string taskToken, IAmazonSimpleWorkflow simpleWorkflow, CancellationToken cancellationToken) { var request = new RespondActivityTaskFailedRequest() { TaskToken = taskToken, Reason = Reason, Details = _details }; await simpleWorkflow.RespondActivityTaskFailedAsync(request, cancellationToken); }
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); }
static void StartWorkflow(string name) { IAmazonSimpleWorkflow swfClient = AWSClientFactory.CreateAmazonSimpleWorkflowClient(); string workflowID = "Hello World WorkflowID - " + DateTime.Now.Ticks.ToString(); swfClient.StartWorkflowExecution(new StartWorkflowExecutionRequest() { Input = "{\"inputparam1\":\"value1\"}", // Serialize input to a string WorkflowId = workflowID, Domain = domainName, WorkflowType = new WorkflowType() { Name = name, Version = "2.0" } }); Console.WriteLine("Setup: Workflow Instance created ID=" + workflowID); }
public static void Worker(IAmazonSimpleWorkflow swfClient, string domainName, string tasklistName) { string prefix = string.Format("Worker{0}:{1:x} ", tasklistName, System.Threading.Thread.CurrentThread.ManagedThreadId); while (true) { Console.WriteLine(prefix + ": Polling for activity task ..."); PollForActivityTaskRequest pollForActivityTaskRequest = new PollForActivityTaskRequest() { Domain = domainName, TaskList = new TaskList() { // Poll only the tasks assigned to me Name = tasklistName } }; PollForActivityTaskResponse pollForActivityTaskResponse = swfClient.PollForActivityTask(pollForActivityTaskRequest); RespondActivityTaskCompletedRequest respondActivityTaskCompletedRequest = new RespondActivityTaskCompletedRequest() { Result = "{\"activityResult1\":\"Result Value1\"}", TaskToken = pollForActivityTaskResponse.ActivityTask.TaskToken }; if (pollForActivityTaskResponse.ActivityTask.ActivityId == null) { Console.WriteLine(prefix + ": NULL"); } else { RespondActivityTaskCompletedResponse respondActivityTaskCompletedResponse = swfClient.RespondActivityTaskCompleted(respondActivityTaskCompletedRequest); Console.WriteLine(prefix + ": Activity task completed. ActivityId - " + pollForActivityTaskResponse.ActivityTask.ActivityId); } } }
public static void RegisterDomain(IAmazonSimpleWorkflow swfClient, string domainName) { // Register if the domain is not already registered. var listDomainRequest = new ListDomainsRequest() { RegistrationStatus = RegistrationStatus.REGISTERED }; if (swfClient.ListDomains(listDomainRequest).DomainInfos.Infos.FirstOrDefault( x => x.Name == domainName) == null) { RegisterDomainRequest request = new RegisterDomainRequest() { Name = domainName, Description = "Hello World Demo", WorkflowExecutionRetentionPeriodInDays = "1" }; Console.WriteLine("Setup: Created Domain - " + domainName); swfClient.RegisterDomain(request); } }
/// <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; }
/// <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; }
internal ListActivityTypesPaginator(IAmazonSimpleWorkflow client, ListActivityTypesRequest request) { this._client = client; this._request = request; }
public ParallelWorkflowCollectionBase(IWorkflowCollectionOptions <TInput, TOutput> collectionOptions, IAmazonSimpleWorkflow swfClient, IStorageManager storeClient) : base(collectionOptions, swfClient, storeClient) { if (collectionOptions == null) { throw new ArgumentNullException(nameof(collectionOptions)); } Options = collectionOptions; }
internal PollForDecisionTaskPaginator(IAmazonSimpleWorkflow client, PollForDecisionTaskRequest request) { this._client = client; this._request = request; }
/// <summary> /// Create a domain with given name and a client to communicate with Amazon SWF. You have more control on creating/configuring the AmazonSimpleWorkflowClient. /// </summary> /// <param name="name"></param> /// <param name="simpleWorkflowClient"></param> public Domain(string name, IAmazonSimpleWorkflow simpleWorkflowClient) : this(name, simpleWorkflowClient, ErrorHandler.NotHandled) { }
internal GetWorkflowExecutionHistoryPaginator(IAmazonSimpleWorkflow client, GetWorkflowExecutionHistoryRequest request) { this._client = client; this._request = request; }
internal abstract Task SendAsync(string taskToken, IAmazonSimpleWorkflow simpleWorkflow, CancellationToken cancellationToken);
internal override Task SendAsync(string taskToken, IAmazonSimpleWorkflow simpleWorkflow, CancellationToken cancellationToken) { return(Task.FromResult(false)); }
private Amazon.SimpleWorkflow.Model.UntagResourceResponse CallAWSServiceOperation(IAmazonSimpleWorkflow client, Amazon.SimpleWorkflow.Model.UntagResourceRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Simple Workflow Service (SWF)", "UntagResource"); try { #if DESKTOP return(client.UntagResource(request)); #elif CORECLR return(client.UntagResourceAsync(request).GetAwaiter().GetResult()); #else #error "Unknown build edition" #endif } catch (AmazonServiceException exc) { var webException = exc.InnerException as System.Net.WebException; if (webException != null) { throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException); } throw; } }
internal ListClosedWorkflowExecutionsPaginator(IAmazonSimpleWorkflow client, ListClosedWorkflowExecutionsRequest request) { this._client = client; this._request = request; }