pallet.algo.fsmop documentation


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.


Operation control protocol.



Abort the operation.



Predicate to test if operation is complete.



Predicate to test if operation is failed.



Return the status of the operation.



wait on the result of the completed operation


[state event event-data]

Default event handler for the :init state


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


[op-name steps result]

A comprehension that results in a compound FSM specification.


[form syms]

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



Execute a function in the operate-executor thread pool.


[f delay delay-units]

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



An operation primitive that does nothing but fail immediately.



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



Execute a set of fsms


[& fsm-configs]

Merge operation primitve FSM's.



op-state stack depth



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



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


[stack v]

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


[state op-state]

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


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


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

Print a report on the status of an operation.



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


[steps result &env]

Takes FSM comprehension forms and translates them


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


[flag fail-reason]

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


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


[state state-kw f & args]

Convenience update function.