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))))))(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))))(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)(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/processoptions. :cmd: likebabashka.process/process. By default is to redirect:errto:out.:regex: the regex to match from either:stdor:error both of the process.:key: the key used to store the process created when returningopts.:capture: either:error: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 invokingdestroy!. 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))))))(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]))})(stop! system)Function.
it stops a system created with :async true.