pallet.algo.fsmop documentation

Operations

Operate provides orchestration. It assumes that operations can succeed, fail, time-out or be aborted. It assumes some things happen in parallel, and that some things need to be sequenced.

Operation primitive FSM contract

An operation primitive must produce a FSM specification.

The FSM must respond to the :start event in it's initial state. The event data sent with the :start event will be the current global state. The default initial state is :init. The default response for the :start event in the :init state is to set the primitive's :state-data to the global state, and to transition to the :running state.

The FSM must have a :completed and a :failed state.

It must respond to the :abort event, which is sent on a user initiated abort of an operation. The :abort event should cause the FSM to end in the :aborted state.

The :init, :completed, :aborted and :failed states will be implicitly added if not declared.

The result should be placed on the :result key of the state-data.

A failure reason should be placed on the :fail-reason key of the state-data.

State event functions (on-enter and on-exit) should return true if they do anything to change the state of the FSM, and further event functions should not be called for the transition.

The `operation` FSM comprehension

An expression under the operation FSM comprehension results in a compound FSM. It is returned as a function, that takes a state, and returns a map of functions to control the resulting FSM.

Control

Operation control protocol.

abort

[_]

Abort the operation.

complete?

[_]

Predicate to test if operation is complete.

failed?

[_]

Predicate to test if operation is failed.

status

[_]

Return the status of the operation.

wait-for

[_]

wait on the result of the completed operation

default-init-event-handler

[state event event-data]

Default event handler for the :init state

delay-for

[delay delay-units]

An operation primitive that does nothing for the given delay. This uses the stateful-fsm's timeout mechanism. Not the timeout primitive. The primitive transitions to :completed after the given delay.

dofsm

[op-name steps result]

A comprehension that results in a compound FSM specification.

eval-in-env-fn

[form syms]

Give a form, return a function of a single env argument and that evaluates the form in the given environment.

execute

[f]

Execute a function in the operate-executor thread pool.

execute-after

[f delay delay-units]

Execute a function after a specified delay in the scheduled-executor thread pool. Returns a ScheduledFuture.

fail

[reason]
[]

An operation primitive that does nothing but fail immediately.

get-op-state

[state]

Get the current op-state map off the ::opt-state key in the FSM's state map.

map*

[fsm-configs]

Execute a set of fsms

merge-fsms

[& fsm-configs]

Merge operation primitve FSM's.

op-state-stack-depth

[state]

op-state stack depth

operate

[operation]

Start the specified operation on the given arguments. The call returns an object that implements the Control protocol.

pop-op-state

[state]

Pop a op-state map off the ::opt-state key in the FSM's state map.

push

[stack v]

Push a value onto a stack, using a vector if the stack is nil.

push-op-state

[state op-state]

Push a new op-state map onto the ::opt-state key in the FSM's state map.

reduce*

[f init-value s]

A reduce function where the passed reducing function f should return a FSM configuration, whose result when executed, will be passed to the next call of the reducing function.

report-operation

[operation & {:keys [env steps history], :as options}]

Print a report on the status of an operation.

result

[value]

An operation primitive that does nothing but succeed immediately with the specified result value.

seq-steps

[steps result &env]

Takes FSM comprehension forms and translates them

set-in-env-fn

[expr &env]

Give an expression that is a valid lhs in a binding, return a function of an env argument and a value that assigns the results of destructuring into env.

succeed

[flag fail-reason]
[flag]
[]

An operation primitive that does nothing but succeed or fail immediately based on the passed flag. The default is to succeed.

timeout

[fsm-config delay delay-units]

Execute an expression with a timeout. The timeout is applied to each state. Any transition out of a state will cancel the timeout.

update-state

[state state-kw f & args]

Convenience update function.