integrant

dobladez 2019-12-20T15:49:00.003600Z

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.

2019-12-20T15:51:25.004Z

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

2019-12-20T15:52:02.004300Z

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.

2019-12-20T15:52:55.005200Z

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.

dobladez 2019-12-20T15:57:51.005400Z

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

dobladez 2019-12-20T15:59:28.005600Z

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

dobladez 2019-12-20T15:59:31.005800Z

thanks

2019-12-20T16:00:17.006Z

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

2019-12-20T16:01:24.006200Z

And a halt key:

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

2019-12-20T16:02:20.006500Z

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.

2019-12-20T16:02:58.006700Z

This is the problem that resolve-key solves:

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

2019-12-20T16:03:19.006900Z

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

dobladez 2019-12-20T16:03:40.007100Z

I see...

dobladez 2019-12-20T16:03:54.007300Z

I'll try to apply it to my case

2019-12-20T16:04:01.007500Z

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.

dobladez 2019-12-20T16:04:06.007700Z

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

dobladez 2019-12-20T16:04:14.007900Z

got it

dobladez 2019-12-20T16:04:29.008100Z

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!

dobladez 2019-12-20T16:05:35.008300Z

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

dobladez 2019-12-20T16:06:30.008500Z

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

onetom 2019-12-20T17:49:18.010100Z

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?

2019-12-20T17:50:10.010900Z

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

2019-12-20T17:50:36.011500Z

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

👍 3
theeternalpulse 2019-12-26T18:36:34.016200Z

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