Amazon Provides Simple Workflow Service Recipes
Amazon just released a whitepaper and code samples containing Amazon Simple Workflow Service Recipes.
Amazon Simple Workflow Service (SWF) is a:
... workflow service for building scalable, resilient applications. Whether automating business processes for finance or insurance applications, building sophisticated data analytics applications, or managing cloud infrastructure services, Amazon SWF reliably coordinates all of the processing steps within an application.
The big advantage of SWF is that it is a fully managed service that does not require any additional investments either in hardware or administration, including tuning, patching or software upgrading. It provides simple APIs and allows the execution of workflow steps either on EC2 or any machine having an Internet connection. The SWF implementation is based on polling, and, as a result, a program running on an internal (to enterprise) machine just polls SWF for new tasks. Finally, the AWS Management Console provides detailed reporting on the current status and execution history of workflows.
The SWF implementation requires adding "decider" code to a new or existing application that defines the work coordination logic by specifying work sequencing, timing, and failure conditions. It is also necessary to implement "activities", which are application components that execute each step of the work. The decider and activities form a "workflow." Once the decider and activities are in place, the SWF service coordinates the work on behalf of the application.
Despite all the advantages of AWS SWF, it is not always easy to produce a SWF implementation, due to lack of examples and best implementation practices. A new whitepaper from Amazon is filling this void by providing a wealth of workflow pattern implementation samples, accompanied by working code, implementing those patterns. The following groups of patterns and implementations are covered:
· Repeated Execution of an activity, including:
o Using a loop for repetitively execution of an activity a specified number of times.
o Recursive execution of asynchronous activity a specified number of times.
o Recursive execution of asynchronous activity while a condition is satisfied.
· Concurrent Execution of multiple Activities, including:
o Fork-Join with a fixed number of activities
o Fork-Join with a dynamically determined number of activities
o Fork multiple activities and use the result from the first activity to complete.
· Conditional Execution of Workflow Logic
o Execution of one of several activities based on a condition.
o Execution of multiple activities from a larger group based on a condition.
· Manual completion of an activity task
o Manual activity implementation.
· Exceptions handling for asynchronous execution
o Handling exceptions thrown by asynchronous code such as activities and clean up resources using try/catch/finally.
o Handling exceptions thrown by asynchronous code by invoking other asynchronous code.
· Retrying failed asynchronous code
o Retrying an activity until it either completes or the retry attempts reach a specified limit.
o Annotating an activity so that the framework retries it automatically by using an exponential retry strategy, which waits for an increasingly long period between each retry, and stops at a specified point.
o Implementing exponential retry by using the RetryDecorator class, which allows specifying the retry policy at run time and change it as needed.
o Implementing exponential retry by using the AsyncRetryingExecutor class, which allows specifying the retry policy at run time. In addition, it shows the usage of the AsyncRunnable abstraction to implement a run method, which AsyncRetryingExecutor calls to execute the activity for each retry attempt.
o Implementing a custom retry strategy.
· Signaling a Workflow
o Implementing a workflow waiting a specified time for a signal before proceeding.
Using the newly published SWF recipes provides a great starting point for the implementation of new custom workflows.
Martin Thompson Jul 27, 2014