book/operation/builtin/config-watcher
Configuration watcher
Assertions requiring a
service with name matching ConfigWatcher cause the server
to start a configuration watcher service monitoring files in and
subdirectories of the given path for changes:
ConfigWatcher = <config-watcher @path string @env ConfigEnv>.
ConfigEnv = { symbol: any ...:... }.
The path may name either a file or directory. Any time
the configuration watcher finds a file matching the glob
*.pr within the tree rooted at path, it loads
the file. Each time a *.pr file is loaded, it is
interpreted as a configuration scripting
language program, with a copy of env as the “initial
environment” for the script.
Whenever a change to a *.pr file is detected, the
configuration watcher reloads the file, discarding previous internal
state related to the file.
Note that a quirk of the config language requires that there exist an
entry in env with key the symbol config and
value an entity reference
(usually denoting a dataspace
entity). However, the config entry need not be the same
as the surrounding $config! A useful pattern is to set up a
new ConfigWatcher with env containing a
config binding pointing to an attenuated reference to the
current config dataspace, or even an entirely fresh dataspace
created specifically for the task.
Copyright © 2021–2023 Tony Garnock-Jones, CC BY 4.0
