Skip to content

Instantly share code, notes, and snippets.

@fogus
Created October 7, 2014 13:20
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fogus/5db69dc7a101e6e3fa40 to your computer and use it in GitHub Desktop.
Save fogus/5db69dc7a101e6e3fa40 to your computer and use it in GitHub Desktop.
(defrecord Server [service-map]
component/Lifecycle
(start [component]
(info :msg "Starting server.")
(let [server (bootstrap/create-server (:service-map service-map))]
(bootstrap/start server)
(assoc component :server server)))
(stop [component]
(info :msg "Stopping server.")
(update-in component [:server] bootstrap/stop)))
(definterceptorfn add-conn
[conn]
(on-request ::add-conn #(assoc % :conn conn)))
(defrecord ServiceMap [service-data conn]
component/Lifecycle
(start [component]
(info :msg "Adding connection interceptor to service-map.")
(let [service-map (update-in service-data
[::bootstrap/interceptors]
conj (add-conn (:conn conn)))]
(assoc component :service-map service-map)))
(stop [component]
(info :msg "Removing connection interceptor from service-map.")
(update-in component
[:service-map ::bootstrap/interceptors]
pop)))
(defn mk-service-map
[conn & [opts]]
(map->ServiceMap {:service-data (merge service/service opts)}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment