Back

resume-key (clj)

(source)

multimethod

(resume-key key value old-value old-impl)
Turn a config value associated with a key into a concrete implementation, but reuse resources (e.g. connections, running threads, etc) from an existing implementation. By default this multimethod calls init-key and ignores the additional argument.

Examples

integrant
(ns integrant.core-test
  (:require #?(:clj  [clojure.test :refer [are deftest is testing]]
               :cljs [cljs.test :refer-macros [are deftest is testing]])
            [integrant.core :as ig]
            [weavejester.dependency :as dep]))

(defmethod ig/init-key ::r [_ v] {:v v})
(defmethod ig/resolve-key ::r [_ {:keys [v]}] v)
(defmethod ig/resume-key ::r [k v _ _] (ig/init-key k v))

(defmethod ig/resume-key :default [k cfg cfg' sys]
  (swap! log conj [:resume k cfg cfg' sys])
  [cfg])

(defmethod ig/resume-key ::x [k cfg cfg' sys]
  (swap! log conj [:resume k cfg cfg' sys])
  :rx)
kit-clj/kit
(ns kit.edge.utils.nrepl
  (:require
    [clojure.tools.logging :as log]
    [integrant.core :as ig]
    [kit.ig-utils :as ig-utils]
    [nrepl.cmdline]
    [nrepl.server :as nrepl]))

(defmethod ig/resume-key :nrepl/server
  [key opts old-opts old-impl]
  (ig-utils/resume-handler key opts old-opts old-impl))
kit-clj/kit
(ns kit.edge.db.sql.conman
  (:require
    [conman.core :as conman]
    [integrant.core :as ig]
    [kit.ig-utils :as ig-utils]))

(defmethod ig/resume-key :db.sql/connection
  [key opts old-opts old-impl]
  (ig-utils/resume-handler key opts old-opts old-impl))

(defmethod ig/resume-key :db.sql/query-fn
  [k {:keys [filename filenames] :as opts} old-opts old-impl]
  (if (and (= opts old-opts)
           (= (map ig-utils/last-modified (or filenames [filename]))
              (:mtimes (meta old-impl))))
    old-impl
    (do (ig/halt-key! k old-impl)
        (ig/init-key k opts))))
kit-clj/kit
(ns kit.edge.db.sql.hikari
  (:require
    [hikari-cp.core :as cp]
    [integrant.core :as ig]
    [kit.ig-utils :as ig-utils]
    ))

(defmethod ig/resume-key :db.sql/hikari-connection
  [key opts old-opts old-impl]
  (ig-utils/resume-handler key opts old-opts old-impl))
kit-clj/kit
(ns kit.edge.scheduling.quartz
  (:require
    [aero.core :as aero]
    [integrant.core :as ig]
    [kit.ig-utils :as ig-utils]
    [troy-west.cronut :as cronut]))

(defmethod ig/resume-key :cronut/scheduler
  [key opts old-opts old-impl]
  (ig-utils/resume-handler key opts old-opts old-impl))
Zetawar/zetawar
(ns zetawar.system.datascript
  (:require
   [datascript.core :as d]
   [integrant.core :as ig]))

(defmethod ig/resume-key :zetawar.system/datascript [_ opts old-opts old-impl]
  (let [{:keys [schema]} opts
        old-schema (:schema old-opts)]
    (if (= schema old-schema)
      old-impl
      {:schema schema
       :conn (d/create-conn schema)})))