Standalone utility functions.
Standalone utility functions.
(alive-millis)
(alive-millis n)
Return a function (fn [])
that when invoked, records the current time as when was the application last alive. You
may deref the same function as (deref f)
to find out the time the application was last alive. Optimized for
concurrent updates; eventually consistent.
Return a function `(fn [])` that when invoked, records the current time as when was the application last alive. You may deref the same function as `(deref f)` to find out the time the application was last alive. Optimized for concurrent updates; eventually consistent.
(as-vec x)
Turn argument into a vector if it is a collection, else wrap the argument into a single-item vector.
Turn argument into a vector if it is a collection, else wrap the argument into a single-item vector.
(clean-uuid)
(clean-uuid uuid)
Generate or convert UUID into a sanitized, lower-case form.
Generate or convert UUID into a sanitized, lower-case form.
(err-print-banner x & more)
Print a banner to *err*
.
Print a banner to `*err*`.
(err-println x & more)
Same as clojure.core/println
for *err*
.
Same as `clojure.core/println` for `*err*`.
(exec-once! a-var & body)
Given a redefinable var e.g. (defonce a-var nil)
having logical false value, set it to true
and evaluate the
body.
Given a redefinable var e.g. `(defonce a-var nil)` having logical false value, set it to `true` and evaluate the body.
(expected expectation found)
(expected pred expectation found)
Throw illegal input exception citing expectation and what was found did not match. Optionally accept a predicate fn to test found before throwing the exception.
Throw illegal input exception citing _expectation_ and what was _found_ did not match. Optionally accept a predicate fn to test _found_ before throwing the exception.
(health-status components)
Given a collection of health status maps (with keys :status
and :impact
) of zero or more components, derive
overall health status and return status map {:status status :components components}
based on the following rules:
Health status :critical
> :degraded
> :healthy
(high to low)
Higher old-status always overrides lower new-status.
Same old-status and new-status are considered unchanged.
A higher new-status is interpreted as follows:
Old status | New status | Impact :direct | Impact :indirect | Impact :noimpact |
---|---|---|---|---|
degraded | critical | critical | degraded | degraded |
healthy | critical | critical | degraded | healthy |
healthy | degraded | degraded | degraded | healthy |
Example of returned status:
{:status :degraded ; derived from components - :critical, :degraded, :healthy (default), :unknown
:components [{:id :mysql
:status :degraded
:impact :hard ; impact on overall health - :hard (default), :soft, :none/nil/false
:breaker :half-open
:retry-in "14000ms"}
{:id :cache
:status :critical
:impact :soft}
{:id :disk
:status :healthy
:impact :none
:free-gb 39.42}]}
Given a collection of health status maps (with keys `:status` and `:impact`) of zero or more components, derive overall health status and return status map `{:status status :components components}` based on the following rules: 0. Health status `:critical` > `:degraded` > `:healthy` (high to low) 1. Higher old-status always overrides lower new-status. 2. Same old-status and new-status are considered unchanged. 3. A higher new-status is interpreted as follows: |Old status|New status|Impact :direct|Impact :indirect|Impact :noimpact| |----------|----------|--------------|----------------|----------------| | degraded | critical | critical | degraded | degraded | | healthy | critical | critical | degraded | healthy | | healthy | degraded | degraded | degraded | healthy | Example of returned status: ```edn {:status :degraded ; derived from components - :critical, :degraded, :healthy (default), :unknown :components [{:id :mysql :status :degraded :impact :hard ; impact on overall health - :hard (default), :soft, :none/nil/false :breaker :half-open :retry-in "14000ms"} {:id :cache :status :critical :impact :soft} {:id :disk :status :healthy :impact :none :free-gb 39.42}]} ```
(invoke f & args)
Invoke first argument as a function on the remaining arguments.
Invoke first argument as a function on the remaining arguments.
(let-var bindings & body)
Given a binding vector where right-hand side is fully-qualified var name symbol and body of code, resolve the vars and evaluate the body of code in the binding context.
Given a binding vector where right-hand side is fully-qualified var name symbol and body of code, resolve the vars and evaluate the body of code in the binding context.
(millis->str millis)
Convert milliseconds to human readable string.
Convert milliseconds to human readable string.
(nbytes->str n)
Convert bytes-count to human readable string.
Convert bytes-count to human readable string.
(now-millis)
(now-millis start-millis)
Return current epochal time in milliseconds.
Return current epochal time in milliseconds.
(pst-when-uncaught-handler e)
(pst-when-uncaught-handler e out)
When uncaught exception handler is configured, print the stack trace.
When uncaught exception handler is configured, print the stack trace.
(set-default-uncaught-exception-handler f)
Set specified function (fn [thread throwable])
as default uncaught exception handler.
Set specified function `(fn [thread throwable])` as default uncaught exception handler.
(shorten-name any-name)
(shorten-name split-regex any-name)
Shorten a stringable name, e.g. foo.bar.baz.qux/fred
to f.b.baz.qux/fred
, leaving only the last two tokens
intact.
Shorten a stringable name, e.g. `foo.bar.baz.qux/fred` to `f.b.baz.qux/fred`, leaving only the last two tokens intact.
(sleep-millis millis)
Sleep for specified number of milliseconds.
Sleep for specified number of milliseconds.
(stack-trace-str e)
Given a throwable (generally an exception) return the stack trace string as it would be printed on a console.
Given a throwable (generally an exception) return the stack trace string as it would be printed on a console.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close