Skip to content

core

A workflow performs a series of steps, threading an opts map through each one.

(->step-fn {:keys [before-f after-f]})

Function.

A step function is a function that accepts three arguments: the step, the step name, and the opts map. To maintain the execution chain, it must return the updated (or original) opts map.

For convenience, ->step-fn allows you to provide two simpler functions. These functions take only two arguments—the step and the opts map—and do not need to return the map. These are typically used for side effects, such as logging to stdout or terminating the process with a specific exit code.

These side-effect functions are executed immediately before and after a workflow step and receive the current execution context.

Source

(->workflow wf-opts)

Function.

Creates a workflow based on the following wf-opts map:

  • :first-step (Required): The qualified keyword representing the initial step in the workflow. Defaults typically to ::start.
  • :last-step (Optional): The qualified keyword for the final step. If omitted, it defaults to ::end, sharing the same namespace as :first-step.
  • :step-fns (Optional): An array of functions to be executed before and after every step. Useful for cross-cutting concerns like logging, telemetry, or tracing.
  • :wire-fn (Required): A function that accepts two arguments—the current step and the step-fns. step-fns is used to invoke subworkflow using partial. It must return a seq of function and next step.
  • :next-fn (Optional): A function used to handle complex or conditional branching logic when the default transitions provided by the wire-fn are insufficient.

Example with of workflow subworkflow:

(let [wf (->workflow {:first-step ::start
:wire-fn (fn [step step-fns]
(case step
::start [#(ok %) ::sub-wf]
::sub-wf [(partial sub-wf step-fns) ::end]
::end [identity]))})]
(wf [my-step-fn] {::my :value})
(wf [my-step-fn] [{::my :value} {::his :value}]))

Example with of workflow with next-fn:

(def lock (->workflow {:first-step ::generate-lock-id
:wire-fn (fn [step _]
(case step
::generate-lock-id [generate-lock-id ::delete-tag]
::delete-tag [delete-tag ::create-tag]
::create-tag [create-tag ::push-tag]
::push-tag [push-tag ::get-remote-tag]
::get-remote-tag [(comp get-remote-tag delete-tag) ::read-tag]
::read-tag [read-tag ::check-tag]
::check-tag [check-tag ::end]
::end [identity]))
:next-fn (fn [step next-step opts]
(case step
::end [nil opts]
::push-tag (choice {:on-success ::end
:on-failure next-step
:opts opts})
::delete-tag [next-step opts]
(choice {:on-success next-step
:on-failure ::end
:opts opts})))}))

A workflow can be invoked with a seq of opts maps.

Source

(choice {:keys [on-success on-failure opts]})

Function.

To be used in the next-fn. See ->workflow

Source

(ok)
(ok opts)

Function.

Return opts with success. Each step must return opts with a :big-config/exit key value greater than or equal to 0, consistent with Unix shell exit codes.

(defn step-a [opts]
...
(merge opts (ok) {::some-new-key value}))
(defn step-b [opts]
...
(ok opts))

Source