Respond to a notification
Find the notification definition and inspect its callers before implementing an observer. The notifier operation determines whether observers collect results, stop at a first result, or fold a value.
Add the appropriate exported observe_... callback to your active module. Keep it short and return the value required by that notification's contract. Move slow work out of synchronous request paths where possible.
Use the Development observer list to verify registration. Test with other modules enabled: an observer that works alone may interact with another observer through priority or return values.
For example, add the header, export, and callback below to mod_garden.erl (merge declarations with existing ones):
-include_lib("zotonic_core/include/zotonic.hrl").
-export([observe_rsc_update_done/2]).
-spec observe_rsc_update_done(Event, Context) -> ok
when Event :: #rsc_update_done{}, Context :: z:context().
observe_rsc_update_done(#rsc_update_done{action = Action, id = Id}, _Context) ->
?LOG_INFO(#{text => <<"Garden observed a resource change">>,
in => mod_garden, action => Action, id => Id}),
ok.
Compile, refresh module discovery, check the observer list, then save a practice page. Expect a log entry with its ID. This notification runs after persistence and ignores the observer's return value. Do not update the same resource unconditionally from this callback: that can trigger the observer again. notification#rsc_update_done and notification#rsc_update have different contracts.
Find registered observers
Open Show an overview of all observers from the Development page. Find the notification and inspect the registered callbacks and their order.
If your callback is absent, check that the module is active, the callback is exported, and the compiled module contains your change. If it is present but has no visible effect, check the notification contract and which caller emits it.
Use a focused trace or log entry to follow one event. Do not add a second observer registration to compensate for an inactive module.