component

roberto 2016-06-13T03:08:10.000002Z

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.

roberto 2016-06-13T03:08:36.000003Z

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)))

donaldball 2016-06-13T03:13:17.000004Z

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.

2016-06-13T03:13:57.000005Z

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

roberto 2016-06-13T03:15:29.000007Z

I was thinking of having a global atom, but it doesn’t feel right

2016-06-13T03:15:53.000008Z

the atoms aren't global, they are values for keys in the component

roberto 2016-06-13T03:16:19.000009Z

oh, I see