Skip to content

system

An alternative to Integrant to create a system using big-config.core/->workflow.

(add-stop-fn opts f)

Function.

It returns opts but f does not return opts. While Integrant has an init-key and an halt-key, here you have only a step and add-stop-fn that adds a f for future invocations to halt the pending resources.

Example:

(defn background-process [opts]
(let [re-opts (into {} [[:cmd cmd ]
[:regex regex]
[:timeout 1000]
[:key ::proc]])
opts (re-process re-opts opts)]
(add-stop-fn opts (fn [{:keys [::proc] :as opts}]
(when proc
(destroy! proc 1000))))))

Source

(destroy! proc & [timeout])

Function.

Destroy a babashka.process/process.

Example:

(add-stop-fn opts (fn [{:keys [::proc] :as opts}]
(when proc
(destroy! proc kill-timeout))))

Source

(env key default-value)

Function.

Map of the environment variables keywordized. All _ are transformed to -. All . are transformed to -. All evironment variables are lowercased. Example

(env :path)

Source

(re-process re-opts opts)

Function.

Creates a child process and blocks until :timeout or the :regex is found. re-opts is pass to babashka.process/process.

Supported options in re-opts:

  • all babashka.process/process options.
  • :cmd: like babashka.process/process. By default is to redirect :err to :out.
  • :regex: the regex to match from either :std or :err or both of the process.
  • :key: the key used to store the process created when returning opts.
  • :capture: either :err or :out. By default is :out.
  • :line-fn: a function to do something with every line. By default it prints to *err* and it flushes it.
  • :timeout: the timeout for finding the :regex. By default is 1 second.
  • :kill-timeout: the timeout for invoking destroy!. By default is 1 second.

Example of re-process

(defn background-process [opts]
(let [re-opts (into {} [[:cmd cmd ]
[:regex regex]
[:timeout 1000]
[:key ::proc]])
opts (re-process re-opts opts)]
(add-stop-fn opts (fn [{:keys [::proc] :as opts}]
(when proc
(destroy! proc 1000))))))

Source

(stop opts)

Function.

it returns the same version of opts that it has received. To be used in the :wire-fn with the last step.

Example:

(->workflow {:first-step ::start
:wire-fn (fn [step _]
(case step
::start [background-process ::end]
::end [stop]))})

Source

(stop! system)

Function.

it stops a system created with :async true.

Source