Fork me on GitHub
#component
<
2016-05-31
>
marco13:05:53

Hi. I want to start a process in a component after it is started and configured. Is this possible out of the box or do I have to create an own lifecycle?

marco13:05:54

I provide a async channel and want to run a (go-loop … (recur)) when everything is in place.

Lambda/Sierra13:05:33

@marco: I'm not sure I understand the question. If you have a component that implements Lifecycle then you can start threads or go's in the start method.

marco13:05:33

I’ll try to use a future for this.

marco13:05:42

But then I don’t have the initialized component. :thinking_face: I have no clue.

marco13:05:24

Ah, got it. I let the new component.

potetm13:05:50

Is there a recommended way of cyclying (stop+start) a single component in a system?

potetm13:05:30

Or, alternatively, is there a reason that shouldn't be done?

Lambda/Sierra14:05:12

@potetm: There is not currently a way to update a single component within a system, such that dependencies/dependents are also updated.

Lambda/Sierra14:05:24

you're welcome!

donaldball16:05:05

I had a sorta similar requirement on a project I’m working on, @potetm. We wanted to be able to make arbitrary changes to the system configuration and safely apply them without having to restart the entire process/webapp. I ended up with a watcher on the config that simply restarts the system at the first idle period after a change.

Lambda/Sierra17:05:26

Another option for managing change in components is to introduce mutable references (Atoms, Refs) into the definition of the component. The state can be modified in a way that is immediately visible to all users of that component.

Lambda/Sierra17:05:22

I'm curious, @donaldball and @potetm, what is your use case for modifying the system after the initial start? Is it just a convenience to speed up restarts during development, or are you changing a running production system? If the latter, how do you ensure code is running with the current version of a component?

donaldball17:05:52

We wanted the ability to e.g. change the database configuration, not change system code.

Lambda/Sierra17:05:45

@donaldball: Was that during development, or in a running production app?

potetm17:05:09

@stuartsierra: It came to mind for the while I was thinking about how we might have many services on a single machine and start/stop them from the repl if need be. Not necessarily for changing code.

donaldball17:05:11

We would like that capability in a running production app

Lambda/Sierra18:05:07

@donaldball: OK, so in that case, what would you expect to be the consequence of changing the database configuration while the app is running? What would happen to outstanding requests using the old configuration? What if the current configuration has been captured in a closure or a local variable in another thread?

donaldball18:05:40

The config watcher sets a latch which prohibits new requests from being processed until the system restarts. All extant requests must finish before the system will be allowed to restart. Requests which fire off threads must block or use a thread pool under control of the system in order for this scheme to be safe, of course.

Lambda/Sierra18:05:49

OK, thanks for the context.

donaldball19:05:38

Hey, thanks for component. This reconfig capability is something I’ve dearly wanted on some previous clojure apps. Having a coherent system lifecycle is a necessary precondition for doing it safely and sanely.

Lambda/Sierra19:05:09

You're welcome! Glad to hear it has been useful to you

marco20:05:09

Finally I seem to get used to it. I really like the design.