integrant 2019-12-20

@dobladez has joined the channel

is there a way to restart a single component? I couldn't find a way to do it. Usecase: I have a component which is a client to a remote unreliable server... I simply what to force a reconnection every so often. Since the connection state is what the init-key returns, the cleanest would be to re-start the the component.

I’d handle this by wrapping the connection in something that restarts it when it disconnects.

You may also find integrant 0.8.0-alpha useful, as it has resolve-key, which allows additional information to be added that doesn’t show up via a ref.

e.g. you could add something to reconnect every so often that would be turned off via halt-key!, but not visible via ig/ref.

Thanks... 😕... will try to make sense of resolve-key

I don't like the first idea... I'd have to manage that state "manually" instead of leveraging IG

Let me give you a small example. Say you had:

(defmethod ig/init-key ::foo [_ v]
  (let [conn (open-conn v)]
    {:conn conn
     :restarter (restart-periodically conn)}))

And a halt key:

(defmethod ig/halt-key! ::foo [_ v]
  (.close (:conn v))
  (stop-restarter (:restarter v)))

Then you could have a connection that’s periodically restarted. But it would be a pain to use, because you’d have to pull the connection out via the :conn key.

This is the problem that resolve-key solves:

(defmethod ig/resolve-key ::foo [_ v]
  (:conn v))

When you use ig/ref, it’ll automatically unwrap the connection.

I'll try to apply it to my case

You could also wrap your connection in a proxy object that restarts if the connection has been closed. This is a solution that’s independent of Integrant.

(which is not a simple connection, but might work)

just FYI... here's what I have:

;; From service-B:
  (ig/suspend-key! ::service-A service-A)
  (ig/resume ::service-A config-A) ;; I don't have config-A!

it might have worked if I had config-A within init-key of ::service-B

(service-B receiving a ref to service-A, and trying to re-start A from B)

What happened to the presentation which the README of integrant mentions? https://skillsmatter.com/skillscasts/9820-enter-integrant Is there a mirror of that talk somewhere?

Skillsmatter very suddenly went into administration last month. I don’t know what happened to all the videos it recorded.

I’m planning on doing another talk on Integrant next year to fill the gap.

👍 3

Interesting, new developments or will it be mostly a re-telling of what it offers.