Extension: TaskWithFinally State¶
The TaskWithFinally
state extends the Task
state to provide a “finally” branch, which will be executed both for successful completion of the task, but also whenever a Catcher
is triggered due to an error in processing.
The “finally” branch will always be executed prior to the NextState
of either the task or the catcher.
No results are returned by the “finally” branch.
-
class
awssl.ext.
TaskWithFinally
(Name=None, Comment='', InputPath='$', OutputPath='$', NextState=None, EndState=None, ResultPath='$', RetryList=None, CatcherList=None, FinallyState=None, ResourceArn=None, TimeoutSeconds=99999999, HeartbeatSeconds=99999999)¶ The
TaskWithFinally
state can be used to invoke either an AWS Lambda function or anActivity
, which provides a general mechanism for all types of processing. The Task supports retries and catching of specified errors to provide structured error handling, as well as supporting Timeout for processing as one of those error types.As its name suggests,
TaskWithFinally
also optionally allows an additional branch to be executed after a successful completion of the task, or if any of theCatcher
s are triggered by an error.Note that the finally branch will not be executed if no
Catcher
traps the error, so it is recommended that aCatcher
is provided that trapsStates.ALL
if the finally branch must always be executed.Either:
EndState
isTrue
andNextState
must beNone
EndState
isFalse
andNextState
must be a valid instance of a class derived fromStateBase
.
Parameters: - Name (str) – [Required] The name of the state within the branch of the state machine
- Comment (str) – [Optional] A comment describing the intent of this pass state
- InputPath (str) – [Optional] Filter on the Input information to be passed to the Pass state. Default is “$”, signifying that all the Input information will be provided
- OutputPath (str) – [Optional] Filter on the Output information to be returned from the Pass state. Default is “$”, signifying that all the result information will be provided
- EndState (bool) – [Optional] Flag indicating if this state terminates a branch of the state machine. Defaults to
False
- NextState (instance of class derived from
StateBase
) – [Optional] Next state to be invoked within this branch. Must not beNone
unlessEndState
isTrue
- ResultPath (str) – [Optional] JSONPath indicating where results should be added to the Input. Defaults to “$”, indicating results replace the Input entirely.
- RetryList – [Optional]
list
ofRetrier
instances corresponding to error states that cause the entire set of branches to be retried - CatcherList – [Optional]
list
ofCatcher
instances corresponding to error states that can be caught and handled by further states being executed in theStateMachine
. - FinallyState – [Optional] First state of the finally branch to be invoked
- ResourceArn – [Required] The Arn for the
Lambda
function orActivity
that theTask
should invoke
Type: RetryList: list of
Retrier
Type: CatcherList: list of
Catcher
Type: FinallyState: Derived from
StateBase
Type: ResourceArn: str
Param: TimeoutSeconds: [Optional] The number of seconds in which the
Task
should completeType: TimeoutSeconds: int
Param: HeartbeatSeconds: [Optional] The number of seconds between heartbeats from an
Activity
, to indicate it is still runningType: HeartbeatSeconds: int
-
clone
(NameFormatString='{}')¶ Returns a clone of this instance, with the clone named per the NameFormatString, to avoid state name clashes.
If this instance is not an end state, then the next state will also be cloned, to establish a complete clone of the branch form this instance onwards.
Parameters: NameFormatString (str) – [Required] The naming template to be applied to generate the name of the new instance. Returns: TaskWithFinally
– A new instance of this instance and any other instances in its branch.
-
get_heartbeat_seconds
()¶ Returns the heartbeat interval for the
TaskWithFinally
. If more than two heartbeats are missed then the state will fail with aStates.Timeout
error.Returns: int – The heartbeat seconds for the state.
-
get_resource_arn
()¶ Returns the Arn of the Lambda or
Activity
that will be invoked by thisTaskWithFinally
.Returns: str – The Arn of the resource to be invoked.
-
get_timeout_seconds
()¶ Returns the timeout seconds for the
TaskWithFinally
, afterwhich aStates.Timeout
error is raised.Returns: int – The timeout seconds for the state.
-
set_heartbeat_seconds
(HeartbeatSeconds=99999999)¶ Sets the heartbeats seconds for the
TaskWithFinally
. If more than two heartbeats are missed then the state will fail with aStates.Timeout
error.If specified, must not be less than zero seconds. Default value is
99999999
.Param: HeartbeatSeconds: [Optional] The number of seconds between heartbeats from an Activity
, to indicate it is still runningType: HeartbeatSeconds: int
-
set_resource_arn
(ResourceArn=None)¶ Sets the Arn of the Lambda of
Activity
to be invoked by thisTaskWithFinally
. Cannot beNone
and must be a valid Arn formatted string.Parameters: ResourceArn – [Required] The Arn for the Lambda
function orActivity
that theTaskWithFinally
should invokeType: ResourceArn: str
-
set_timeout_seconds
(TimeoutSeconds=99999999)¶ Sets the timeout seconds for the
TaskWithFinally
, afterwhich aStates.Timeout
error is raised.If specified, must not be less than zero seconds. Default value is
99999999
.Param: TimeoutSeconds: [Optional] The number of seconds in which the TaskWithFinally
should completeType: TimeoutSeconds: int