Skip to content
Anthony Schiochet edited this page Jan 18, 2017 · 12 revisions

Welcome to the swiffer wiki!

Getting Started

Maven: TODO

Create tasks:

Create a decider:

Start your workflow

Features

User guide

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.

Activity type definitions

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 {
///
}

other attributes

  • defaultTaskList
  • defaultTaskScheduleToCloseTimeout: unlimited by default, or duration
  • defaultTaskScheduleToStartTimeout: unlimited by default, or duration
  • defaultTaskStartToCloseTimeout: unlimited by default, or duration

timeouts

TODO

input/outputs

TODO: can define custom serializer/unserializer for input & output

tasklist

TODO

Activity Executor

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

Input/output serialization

TODO: default ser/deser for input and output TODO: overriding the ser/deser

Other arguments

TODO: TaskContext TODO: History TODO: State

###Heartbeat and task cancellation TODO

Worker

A worker is defined by:

  1. providing the activity executors
  2. defining the polling strategy
  3. 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

async VS sync

TODO You can provide an executorService to invoke activity executor in a multi-threaded way.

Decider

A decider represents a set of event handler methods that reflect the logic of a workflow type.

A decider is created by:

  1. creating event handler methods that make decisions
  2. creating a poller that will poll a takslist and delegate decisions to the event handlers 3 affecting the handelrs + poller to a Workflow type

Polling

  • domain
  • identity
  • taskList

Reacting to events

General syntax

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 Decisions
  • a state object to be registered as a state marker

Exceptions: TODO will lead to a fatal error!

Activity events

ActivityTaskCompleted
	@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){
		
	}
ActivityTaskFailed
	@OnActivityTaskFailed
	@ParseInteger
	public void onParseInteger(String reason, String details, Decisions decideTo){
		
	}
Other activity events TODO
  • ActivityTaskTimedOut: The activity task timed out.
  • ActivityTaskCancelRequested TODO
  • ActivityTaskCanceled TODO
  • ActivityTaskScheduled TODO
  • ActivityTaskStarted TODO
  • StartActivityTaskFailed
  • ScheduleActivityTaskFailed
  • RequestCancelActivityTaskFailed

Timer events

TimerFired
	@OnTimerFired("cartExpired")
	public void onCartExpired(@Nullable String control, Decisions decideTo){
		
	}
Other timer events (TODO)
  • TimerCanceled
  • TimerStarted
  • StartTimerFailed
  • CancelTimerFailed

WorkflowExecution events

WorkflowExecutionStarted
	@OnWorkflowExecutionStarted
	public void onStart(@Nullable String input){
		
	}
WorkflowExecutionSignaled

Notes: signal can be sent from externally, or from another workflow (even from the same?)

	@OnSignalReceived("signalName")
	public void onSOSReceivedFromCustomerSupport(@Nullable String input){
		
	}
TODO:
  • 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.

Child workflow events

  • 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.

DecisionTask events (TODO)

  • 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.

Marker events (TODO)

  • MarkerRecorded
  • RecordMarkerFailed

HighLevel features

  • retry
  • schedule after unless
  1. state management
  2. common arguments
  3. making decisions

annotationAttributes

  • DecisionContext
  • State

ser/deser of data

TODO

state management

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)

External

###Starting workflow ###Signaling workflow ###Requesting workflow cancellation ###Terminating workflow ###Monitoring (count, list, descirbe, get history)

Configuration

Features that are not yet implemented

  • task priorities, configuration of task priorities

Create Activity tasks

Table of Contents

    Clone this wiki locally