Eai. Hub. Reloader
(eai v0.1.14)
Copy Markdown
Hot-reloads hook modules from config/hooks/*.exs.
Reload flow
- Scan
config/hooks/for*.exsfiles (sorted by filename = priority prefix). Code.compile_file/1each file — this defines the hook module in the BEAM.- Collect
{module, priority}pairs viamodule.__hook_entry__/0. - Pass sorted entries to
Eai.Hub.Pipeline.register/1→ stored in:persistent_term.
Why Code.compile_file instead of Code.eval_file?
compile_file creates proper BEAM modules (registered in code server),
while eval_file only evaluates expressions in the current binding context.
Hot-reloading requires proper module registration so that subsequent calls
to the hook module dispatch via the BEAM's standard module lookup.
Why Code.compile_string for Hub regeneration (see hub.ex)?
The Hub module itself is regenerated (not the hook files). We use
compile_string so we can build source dynamically from the registry,
embedding the hook list directly. The hook files themselves use
compile_file — they are static source files.
Safety
- Files that fail to compile are skipped with a Logger warning; the rest of the reload still proceeds.
- Old hook registrations are fully replaced on each reload (no
accumulation across reloads).
:persistent_term.putis atomic.
Summary
Functions
@spec reload!() :: :ok | {:error, term()}
Reload all hooks from config/hooks/*.exs.
Returns :ok on success, {:error, reason} if the hooks directory
cannot be read. Individual file compile failures are logged but do not
cause an error return.