Skip to content

Instantly share code, notes, and snippets.

@martinhynar
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinhynar/25abd9fb3e1ac88a9030 to your computer and use it in GitHub Desktop.
Save martinhynar/25abd9fb3e1ac88a9030 to your computer and use it in GitHub Desktop.
Correct usage of component
;; This is a function that needs 'resource' started/stopped by the component
(defn index-create [name]
(let [conn (esr/connect (es-url) {:connection-manager __HOW_TO_PASS_COMPONENT_HERE__})]
(esi/create conn name)
))
;; A component that takes care of starting and stopping and stopping http connection manager
(defrecord ElasticSearch []
component/Lifecycle
(start [this]
(let [cm (make-reusable-conn-manager (:connection-manager-conf this))]
(assoc this :connection-manager cm)))
(stop [this]
(let [cm (:connection-manager this)]
(shutdown-manager cm)
(assoc this :connection-manager nil)))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment