-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Welcome to the swiffer wiki!
Maven: TODO
Create tasks:
Create a decider:
Start your workflow
You have to define several things:
- Activity definitions: used to reference the task in deciders and workers, and to automatically register the activity type in AWS SWF
- Activity executor: the job that is going to be done by a scheduled activity
- Worker: a poller that is going to poll for activity tasks, and invoke activity worker
- Decider defintions: the logic and workflow that schedule tasks, start timers, etc.
You can define activities on java methods but it is not recommended because you will not be able to reuse the definition in the decider side:
@ActivityType(name = PARSE_INTEGER_TASK_NAME, version = PARSE_INTEGER_TASK_VERSION)
public Integer parseInteger(String input){
//...
}
It is preferred to define activites as dedicated interfaces, so that you can share that definition in deciders:
@ActivityType(name = PARSE_INTEGER_TASK_NAME, version = PARSE_INTEGER_TASK_VERSION)
public static interface ParseInteger{
//...
}
Or even by defining annotations:
@ActivityType(name = Constants.PARSE_INTEGER_TASK_NAME, version = Constants.PARSE_INTEGER_TASK_VERSION)
public static @interface ParseInteger {
///
}
defaultTaskList
-
defaultTaskScheduleToCloseTimeout
: unlimited by default, or duration -
defaultTaskScheduleToStartTimeout
: unlimited by default, or duration -
defaultTaskStartToCloseTimeout
: unlimited by default, or duration
TODO
TODO: can define custom serializer/unserializer for input & output
TODO
The executor
ifs the code that is executed when an ActivityTask
is polled from a task list
.
You define executors by using the @Executor
annotation:
@Executor(activity = ParseInteger.class)
public Integer parseInteger(final String input) {
// ...return null;
}
[RETHINK]: Alternatively, if the activity has been defined using an annotation:
@ParseInteger
public Integer parseInteger(final String input) {
// ...return null;
}
The return value become the result
attribute of a RespondActivityTaskCompleted result (result=32768)
Exceptions
thrown by the executor are automatically handled and converted into a RespondActivityTaskFailed action.
TODO: can define custom serializer/unserializer for input & output
TODO: define how the exception fiedlds are mapped to TaskFailed attributes (reason 256,details 32768)
TODO: how to change this behavior
TODO: default ser/deser for input and output TODO: overriding the ser/deser
TODO: TaskContext TODO: History TODO: State
###Heartbeat and task cancellation TODO
A worker is defined by:
- providing the activity executors
- defining the polling strategy
- starting and stopping the polling
final AmazonSimpleWorkflow amazonSimpleWorkflow = ...;
final Worker worker = new Worker.Builder()
.client(amazonSimpleWorkflow)//AWS client
.domain(DOMAIN_NAME)//name of the domain containing the taskList to be polled, and in which to register ActivityTypes
.taskList("myTaskList")//l=256, tasklist to be polled, must be shared with the decider scheduling tasks;
.identity("myWorker")//optional l=256, name of the worker, will be store in ActivityTaskStarted events after polling the activity tasks
.with(new ClassContainingMethodsAnnotatedWithExecutor(), new AnotherClassContainingMethodsAnnotatedWithExecutor())
.build();
worker.start();// non-blocking
worker.stop();// non-blocking
TODO You can provide an executorService to invoke activity executor in a multi-threaded way.
A decider represents a set of event handler methods
that reflect the logic
of a workflow type.
A decider is created by:
- creating event handler methods that make decisions
- creating a poller that will poll a takslist and delegate decisions to the event handlers 3 affecting the handelrs + poller to a Workflow type
- domain
- identity
- taskList
You react to events by annotating a method with a provided @On... annotation The method can take arbitrary arguments depending on the type of event.
@On<<EventHappened>>(annotationAttributes)
public void onBusinessEvent(Decisions decideTo, otherMethodParameters){
//make decisions
decideTo.scheduleTask(ParseInteger.class).withInput("").and()
.startTimer("myTimer",50, SECONDS);
}
Common method arguments:
- low-level event attributes
- low-level event class
- DecisionContext
- state
- Decisions: the object to create decisions
Return type:
- void
- a list, iterable or array of
Decision
s - a state object to be registered as a state marker
Exceptions: TODO will lead to a fatal error!
@OnActivityTaskCompleted(activity=ParseInteger.class)
public void onParseInteger(Integer output, Decisions decideTo){
}
or, if the activity is defined with an annotation:
@OnActivityTaskCompleted
@ParseInteger
public void onParseInteger(Integer output, Decisions decideTo){
}
@OnActivityTaskFailed
@ParseInteger
public void onParseInteger(String reason, String details, Decisions decideTo){
}
- ActivityTaskTimedOut: The activity task timed out.
- ActivityTaskCancelRequested TODO
- ActivityTaskCanceled TODO
- ActivityTaskScheduled TODO
- ActivityTaskStarted TODO
- StartActivityTaskFailed
- ScheduleActivityTaskFailed
- RequestCancelActivityTaskFailed
@OnTimerFired("cartExpired")
public void onCartExpired(@Nullable String control, Decisions decideTo){
}
- TimerCanceled
- TimerStarted
- StartTimerFailed
- CancelTimerFailed
@OnWorkflowExecutionStarted
public void onStart(@Nullable String input){
}
Notes: signal can be sent from externally, or from another workflow (even from the same?)
@OnSignalReceived("signalName")
public void onSOSReceivedFromCustomerSupport(@Nullable String input){
}
- WorkflowExecutionCanceled: The workflow execution was successfully canceled and closed.
- WorkflowExecutionCompleted: The workflow execution was closed due to successful completion.
- WorkflowExecutionContinuedAsNew: The workflow execution was closed and a new execution of the same type was created with the same workflowId.
- WorkflowExecutionTerminated: The workflow execution was terminated.
- WorkflowExecutionCancelRequested: A request to cancel this workflow execution was made.
- WorkflowExecutionTimedOut: The workflow execution was closed because a time out was exceeded.
- WorkflowExecutionFailed: The workflow execution closed due to a failure.
- CancelWorkflowExecutionFailed: A request to cancel a workflow execution failed.
- CompleteWorkflowExecutionFailed: The workflow execution failed to complete.
- ContinueAsNewWorkflowExecutionFailed: The workflow execution failed to complete after being continued as a new workflow execution.
- FailWorkflowExecutionFailed: A request to mark a workflow execution as failed, itself failed.
-
StartChildWorkflowExecutionInitiated: A request was made to start a child workflow execution.
-
ChildWorkflowExecutionCanceled: A child workflow execution, started by this workflow execution, was canceled and closed.
-
ChildWorkflowExecutionCompleted: A child workflow execution, started by this workflow execution, completed successfully and was closed.
-
ChildWorkflowExecutionFailed: A child workflow execution, started by this workflow execution, failed to complete successfully and was closed.
-
ChildWorkflowExecutionStarted: A child workflow execution was successfully started.
-
ChildWorkflowExecutionTerminated: A child workflow execution, started by this workflow execution, was terminated.
-
ChildWorkflowExecutionTimedOut: A child workflow execution, started by this workflow execution, timed out and was closed.
-
StartChildWorkflowExecutionFailed: Failed to process StartChildWorkflowExecution decision. This happens when the decision is not configured properly, for example the workflow type specified is not registered.
-
ExternalWorkflowExecutionCancelRequested: Request to cancel an external workflow execution was successfully delivered to the target execution.
-
ExternalWorkflowExecutionSignaled: A signal, requested by this workflow execution, was successfully delivered to the target external workflow execution.
-
RequestCancelExternalWorkflowExecutionInitiated: A request was made to request the cancellation of an external workflow execution.
-
SignalExternalWorkflowExecutionInitiated: A request to signal an external workflow was made.
-
RequestCancelExternalWorkflowExecutionFailed: Request to cancel an external workflow execution failed.
-
SignalExternalWorkflowExecutionFailed: The request to signal an external workflow execution failed.
- DecisionTaskCompleted: The decider successfully completed a decision task by calling RespondDecisionTaskCompleted.
- DecisionTaskScheduled: A decision task was scheduled for the workflow execution.
- DecisionTaskStarted: The decision task was dispatched to a decider.
- DecisionTaskTimedOut: The decision task timed out.
- MarkerRecorded
- RecordMarkerFailed
- retry
- schedule after unless
- state management
- common arguments
- making decisions
- DecisionContext
- State
TODO
TODO
operations to look for: TODO: register workflow type ###other attributes
-
domain: "string",
-
name: "string",
-
version: "string"
-
defaultChildPolicy: "string", TODO see child workflows
-
defaultExecutionStartToCloseTimeout: "string", (timeout for the entire WF or sub WF)
-
defaultLambdaRole: "string",
-
defaultTaskList: for decision tasks, can be overriden when starting WF or subWF
-
defaultTaskPriority: "string",
-
defaultTaskStartToCloseTimeout: "string", for task timeouts
-
description: "string",l=1024
TODO: poll for decision tasks TODO: respond decision tasks
###Decisions ####Child workflow TODO (see defaultChildPolicy config)
###Starting workflow ###Signaling workflow ###Requesting workflow cancellation ###Terminating workflow ###Monitoring (count, list, descirbe, get history)
- task priorities, configuration of task priorities