I have the code bellow for my Pedestal component. When Stuart Sierra's library starts my system-map, the method start implemented in the Pedestal defrecord gets called and it returns an updated version of my component with :pedestal-server associated. Shouldn't the lifecycle manager propagate the updated component so it could be used by the stop method? Whenever I try to stop the server by calling (component/stop (system)) in the REPL, nothing happens because the :pedestal-server key is set to nil.
(defrecord Pedestal [service-map pedestal-server]
component/Lifecycle
(start [this]
(if pedestal-server
this
(assoc this :pedestal-server
(-> service-map
http/create-server
http/start))))
(stop [this]
(when pedestal-server
(http/stop pedestal-server))
(assoc this :pedestal-server nil)))
(defn new-pedestal []
(map->Pedestal {}))
You should note that calling
(com.stuartsierra.component/start)on a component the function returns a started copy of the component but it does not modify the component itself. Likewise calling(com.stuartsierra.component/stop)will return a stopped copy of the component.I think that the value of
:pedestal-serverkey is nil because you did not store the returned value of the(start)call but you called it on the original (unstarted) component.You need to store the state of the application in some storage, like an atom or a var. Then you can update the state of the storage with
startandstop.For example: