config-rs icon indicating copy to clipboard operation
config-rs copied to clipboard

Pick up configuration file changes

Open dtolnay opened this issue 9 years ago • 3 comments

  1. c.merge(/* config.yml */)
  2. c.get("k")
  3. modify config.yml -> k
  4. c.get("k")

The second get should reflect the changes to the config file.

I think we get this for free with the DeserializeSeed approach proposed in #13.

dtolnay avatar Feb 15 '17 06:02 dtolnay

This would either require watching the file for changes, or re-reading all config on every get, both of which have performance implications that would not acceptable in every application. I think this would be a great feature, as long as there is still a way to read config just once.

tmccombs avatar Feb 15 '17 06:02 tmccombs

Yeah.. I definitely want this as there are lot of use cases that could benefit. Here is the API in my head:

c.merge(File::with_name("Settings"));
c.get("key"); //= 1

c.watch(|| {
  // Do something when your config changes
});

Without calling c.watch, the configuration would not watch FS or listen for write events in Etcd.

This issue made me remember about #20. We should probably get that story down first before tackling automatic refresh.

mehcode avatar Feb 15 '17 09:02 mehcode

This is now possible ( check out https://github.com/mehcode/config-rs/blob/master/examples/watch/src/main.rs )

A couple more questions to answer before .watch should be added.

  1. Is Config.watch stating that we are watching all sources? I'd think so.

  2. Should there be a way to opt-out or opt-in to watching at a per-source level?

mehcode avatar Jun 23 '17 07:06 mehcode