0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-03 21:09:00 -05:00

📎 Allow set statement timeout on db module

This commit is contained in:
Andrey Antukh 2022-07-04 13:34:17 +02:00
parent a3580a5ab9
commit 70028e1371

View file

@ -7,6 +7,7 @@
(ns app.db (ns app.db
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.exceptions :as ex] [app.common.exceptions :as ex]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.logging :as l] [app.common.logging :as l]
@ -60,17 +61,22 @@
(s/def ::validation-timeout ::us/integer) (s/def ::validation-timeout ::us/integer)
(s/def ::read-only? ::us/boolean) (s/def ::read-only? ::us/boolean)
(s/def ::statement-timeout ::us/integer)
(s/def ::idle-in-transaction-timeout ::us/integer)
(s/def ::pool-options (s/def ::pool-options
(s/keys :opt-un [::uri ::name (s/keys :opt-un [::uri ::name
::min-size ::min-size
::max-size ::max-size
::connection-timeout ::connection-timeout
::validation-timeout ::validation-timeout
::statement-timeout
::idle-in-transaction-timeout
::migrations ::migrations
::username ::username
::password ::password
::mtx/metrics ::read-only?
::read-only?])) ::mtx/metrics]))
(def defaults (def defaults
{:name :main {:name :main
@ -80,6 +86,8 @@
:validation-timeout 10000 :validation-timeout 10000
:idle-timeout 120000 ; 2min :idle-timeout 120000 ; 2min
:max-lifetime 1800000 ; 30m :max-lifetime 1800000 ; 30m
:statement-timeout 300000
:idle-in-transaction-timeout 300000
:read-only? false}) :read-only? false})
(defmethod ig/prep-key ::pool (defmethod ig/prep-key ::pool
@ -127,10 +135,6 @@
;; API & Impl ;; API & Impl
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def initsql
(str "SET statement_timeout = 300000;\n"
"SET idle_in_transaction_session_timeout = 300000;"))
(defn- create-datasource-config (defn- create-datasource-config
[{:keys [metrics uri] :as cfg}] [{:keys [metrics uri] :as cfg}]
(let [config (HikariConfig.)] (let [config (HikariConfig.)]
@ -145,7 +149,11 @@
(.setMaxLifetime (:max-lifetime cfg)) (.setMaxLifetime (:max-lifetime cfg))
(.setMinimumIdle (:min-size cfg)) (.setMinimumIdle (:min-size cfg))
(.setMaximumPoolSize (:max-size cfg)) (.setMaximumPoolSize (:max-size cfg))
(.setConnectionInitSql initsql) (.setConnectionInitSql
(dm/fmt "SET statement_timeout=%; SET idle_in_transaction_session_timeout=%;"
(:statement-timeout cfg)
(:idle-in-transaction-timeout cfg)))
(.setInitializationFailTimeout -1)) (.setInitializationFailTimeout -1))
;; When metrics namespace is provided ;; When metrics namespace is provided