has anyone had the need to update a component in place. I have a situation where I created a component that connects to a third party api and holds an auth token that expires in 24 hours. So I need to update that token periodically.
this is an example of how my component looks:
(defprotocol Authentication
(authenticate [this]))
(defrecord QBaseAPI [username password app-token]
Authentication
(authenticate [this]
(let [ticket (-> (auth username password) :body xml->ticket)]
(assoc this :ticket ticket)))
component/Lifecycle
(start [this]
(authenticate this))
(stop [this]
(assoc this :username nil :password nil :app-token nil :ticket nil)))
(defn create-qbaseapi-component
[cfg]
(let [username (:username cfg)
password (:password cfg)
app-token (:app-token cfg)]
(->QBaseAPI username password app-token)))
I’m working on something similar right now, actually. The model I’m trying to implement involves a worker being spawned at start to refresh the state, with the component being derefable to yield the state.
this (https://github.com/hiredman/songs-of-future-past/blob/master/src/com/manigfeald/sofp/history.clj#L51-L97) extremely gross code spawns a worker that writes to some atoms periodically
I was thinking of having a global atom, but it doesn’t feel right
the atoms aren't global, they are values for keys in the component
oh, I see