-
Notifications
You must be signed in to change notification settings - Fork 0
/
hikari_cp.clj
36 lines (33 loc) · 896 Bytes
/
hikari_cp.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(ns toyokumo.commons.db.hikari-cp
(:require
[clojure.tools.logging :as log]
[com.stuartsierra.component :as component]
[hikari-cp.core :as hc]
[next.jdbc :as jdbc]
[next.jdbc.protocols :as jdbc.proto]
[toyokumo.commons.health :as health])
(:import
(javax.sql
DataSource)))
(defrecord HikariCP [opts ^DataSource datasource]
component/Lifecycle
(start [this]
(if datasource
this
(assoc this :datasource (hc/make-datasource opts))))
(stop [this]
(when datasource
(hc/close-datasource datasource))
(assoc this :datasource nil))
jdbc.proto/Sourceable
(get-datasource [_]
datasource)
health/HealthCheck
(-alive? [this]
(if datasource
(try
(= 1 (:alive (jdbc/execute-one! this ["select 1 as alive"])))
(catch Exception e
(log/error "HikariCP is dead" e)
false))
false)))