loganasherjones / yapconf

Yet Another Python Configuration
http://yapconf.readthedocs.io/en/stable/
MIT License
18 stars 4 forks source link

Yapconf Watcher #36

Closed loganasherjones closed 6 years ago

loganasherjones commented 6 years ago

It would be nice to be able to list a particular item as a 'watched' item. We would be constantly watching for changes to that item via some source. I need to flesh this out a little bit more, but something like this:

config = spec.load_config(source1, source2, source3)
thread = threading.Thread(target=spec.watch, config)
thread.start()
thread.daemon()

Or possibly something like

config = spec.load_config(source1, source2, source3)
spec.spawn_watcher(config, source1, source2, source3)

That way you could specify which configs you want to watch.

loganasherjones commented 6 years ago

Okay, I think I've settled on the following:

def handle_config_change(old_config, new_config):
    #TODO: Handle config change
    pass

spec.add_source('label', 'json', filename='/path/to/json')
spec.spawn_watcher('label', target=handle_config_change)

In addition, you should be able to specify targets for individual config items:

def handle_foo_change(old_foo, new_foo):
    # TODO: Handle foo change
    pass

spec = YapconfSpec({'foo': {'watch_target': handle_foo_change}})
spec.add_source('label', 'json', filename='/path/to/json')
spec.spawn_watcher('label')