Standalone utility functions.
Standalone utility functions.
(after & body)
Create a function (fn [arg]) -> arg
that returns the supplied argument after evaluating body of code.
Create a function `(fn [arg]) -> arg` that returns the supplied argument after evaluating body of code.
(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.
(doafter expr & body)
Evaluate supplied expression and return it after evaluating body of code.
Evaluate supplied expression and return it after evaluating body of code.
(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.
(thrown->val [klass value & more] & body)
Execute body
of code in a try
block, returning value
when an exception of type klass
is caught.
There may be one of more klass/value pairs, laid out as catch
expressions in the same order as specified.
The caught exceptions are rethrown using clojure.core/future
- to be handled by uncaught-exception handler.
Execute `body` of code in a `try` block, returning `value` when an exception of type `klass` is caught. There may be one of more klass/value pairs, laid out as `catch` expressions in the same order as specified. The caught exceptions are rethrown using `clojure.core/future` - to be handled by uncaught-exception handler.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close