Provides a data source check function for salutem.
Provides a data source check function for salutem.
(data-source-check-fn data-source)
(data-source-check-fn data-source
{:keys [query-sql-params query-timeout query-opts
query-results-result-fn failure-reason-fn
exception-result-fn]})
Returns a check function for the provided javax.sql.DataSource.
Accepts the following options in the option map:
:query-sql-params
: an SQL parameter vector (as defined in
next.jdbc
) or a function
of context that will return an SQL parameter vector containing the
health check query to execute against the data source, defaults to
["SELECT 1 AS up;"]
.:query-timeout
: a [[salutem.core/duration]] or a function of context
that will return a [[salutem.core/duration]] representing the amount of
time to wait for the query to finish before considering it failed;
defaults to 5 seconds.:query-opts
: additional options (as defined in
next.jdbc
) or a function
of context that will return additional options to pass at query execution
time; by default, includes a builder function for rows that returns
unqualified kebab-cased maps; additional options are merged into the
default option map.:query-results-result-fn
: a function, of context and the results of the
query, used to produce a result for the check; by default, a healthy
result is returned, including the contents of the first record from the
results.:failure-reason-fn
: a function, of context and an exception, to
determine the reason for a failure; by default uses failure-reason
.:exception-result-fn
: a function, of context and an exception, used to
produce a result for the check in the case that an exception is thrown;
by default, an unhealthy result is returned including a :salutem/reason
entry with the reason derived by :failure-reason-fn
and a
:salutem/exception
entry containing the thrown exception.If the returned check function is invoked with a context map including a
:logger
key with a
cartus.core/Logger
value, the check function will emit a number of log events whilst
executing.
Returns a check function for the provided [javax.sql.DataSource](https://docs.oracle.com/en/java/javase/11/docs/api/java.sql/javax/sql/DataSource.html). Accepts the following options in the option map: - `:query-sql-params`: an SQL parameter vector (as defined in [`next.jdbc`](https://github.com/seancorfield/next-jdbc)) or a function of context that will return an SQL parameter vector containing the health check query to execute against the data source, defaults to `["SELECT 1 AS up;"]`. - `:query-timeout`: a [[salutem.core/duration]] or a function of context that will return a [[salutem.core/duration]] representing the amount of time to wait for the query to finish before considering it failed; defaults to 5 seconds. - `:query-opts`: additional options (as defined in [`next.jdbc`](https://github.com/seancorfield/next-jdbc)) or a function of context that will return additional options to pass at query execution time; by default, includes a builder function for rows that returns unqualified kebab-cased maps; additional options are merged into the default option map. - `:query-results-result-fn`: a function, of context and the results of the query, used to produce a result for the check; by default, a healthy result is returned, including the contents of the first record from the results. - `:failure-reason-fn`: a function, of context and an exception, to determine the reason for a failure; by default uses [[failure-reason]]. - `:exception-result-fn`: a function, of context and an exception, used to produce a result for the check in the case that an exception is thrown; by default, an unhealthy result is returned including a `:salutem/reason` entry with the reason derived by `:failure-reason-fn` and a `:salutem/exception` entry containing the thrown exception. If the returned check function is invoked with a context map including a `:logger` key with a [`cartus.core/Logger`](https://logicblocks.github.io/cartus/cartus.core.html#var-Logger) value, the check function will emit a number of log events whilst executing.
(failure-reason exception)
Determines the failure reason associated with an exception.
This failure reason function, the default used by the check function, uses a
reason of :threw-exception
for all exceptions other than a
java.sql.SQLTimeoutException
for which the reason is :timed-out
.
In the case that this default behaviour is insufficient, an alternative
failure reason function can be passed to data-source-check-fn
using the
:failure-reason-fn
option.
Determines the failure reason associated with an exception. This failure reason function, the default used by the check function, uses a reason of `:threw-exception` for all exceptions other than a [java.sql.SQLTimeoutException](https://docs.oracle.com/en/java/javase/11/docs/api/java.sql/java/sql/SQLTimeoutException.html) for which the reason is `:timed-out`. In the case that this default behaviour is insufficient, an alternative failure reason function can be passed to [[data-source-check-fn]] using the `:failure-reason-fn` option.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close