@@ -2839,74 +2839,88 @@ clear_many_payloads(StoreId, PathPattern, Options) ->
28392839% % register_trigger().
28402840% % -------------------------------------------------------------------
28412841
2842- -spec register_trigger (TriggerId , EventFilter , StoredProcPath ) -> Ret when
2842+ -spec register_trigger (TriggerId , EventFilter , Action ) -> Ret when
28432843 TriggerId :: trigger_id (),
28442844 EventFilter :: khepri_evf :event_filter_or_compat (),
2845+ Action :: StoredProcPath |
2846+ Pid |
2847+ khepri_event_handler :trigger_action (),
28452848 StoredProcPath :: khepri_path :path (),
2849+ Pid :: pid (),
28462850 Ret :: ok | error ().
28472851% % @doc Registers a trigger.
28482852% %
28492853% % Calling this function is the same as calling `register_trigger(StoreId,
2850- % % TriggerId, EventFilter, StoredProcPath )' with the default store ID (see
2854+ % % TriggerId, EventFilter, Action )' with the default store ID (see
28512855% % {@link khepri_cluster:get_default_store_id/0}).
28522856% %
28532857% % @see register_trigger/4.
28542858
2855- register_trigger (TriggerId , EventFilter , StoredProcPath ) ->
2859+ register_trigger (TriggerId , EventFilter , Action ) ->
28562860 StoreId = khepri_cluster :get_default_store_id (),
2857- register_trigger (StoreId , TriggerId , EventFilter , StoredProcPath ).
2861+ register_trigger (StoreId , TriggerId , EventFilter , Action ).
28582862
28592863-spec register_trigger
2860- (StoreId , TriggerId , EventFilter , StoredProcPath ) -> Ret when
2864+ (StoreId , TriggerId , EventFilter , Action ) -> Ret when
28612865 StoreId :: khepri :store_id (),
28622866 TriggerId :: trigger_id (),
28632867 EventFilter :: khepri_evf :event_filter_or_compat (),
2868+ Action :: StoredProcPath |
2869+ Pid |
2870+ khepri_event_handler :trigger_action (),
28642871 StoredProcPath :: khepri_path :path (),
2872+ Pid :: pid (),
28652873 Ret :: ok | error ();
2866- (TriggerId , EventFilter , StoredProcPath , Options ) -> Ret when
2874+ (TriggerId , EventFilter , Action , Options ) -> Ret when
28672875 TriggerId :: trigger_id (),
28682876 EventFilter :: khepri_evf :event_filter_or_compat (),
2877+ Action :: StoredProcPath |
2878+ Pid |
2879+ khepri_event_handler :trigger_action (),
28692880 StoredProcPath :: khepri_path :path (),
2881+ Pid :: pid (),
28702882 Options :: command_options () | khepri :trigger_options (),
28712883 Ret :: ok | error ().
28722884% % @doc Registers a trigger.
28732885% %
28742886% % This function accepts the following two forms:
28752887% % <ul>
2876- % % <li>`register_trigger(StoreId, TriggerId, EventFilter, StoredProcPath )'.
2888+ % % <li>`register_trigger(StoreId, TriggerId, EventFilter, Action )'.
28772889% % Calling it is the same as calling `register_trigger(StoreId, TriggerId,
2878- % % EventFilter, StoredProcPath , #{})'.</li>
2879- % % <li>`register_trigger(TriggerId, EventFilter, StoredProcPath , Options)'.
2890+ % % EventFilter, Action , #{})'.</li>
2891+ % % <li>`register_trigger(TriggerId, EventFilter, Action , Options)'.
28802892% % Calling it is the same as calling `register_trigger(StoreId, TriggerId,
2881- % % EventFilter, StoredProcPath , Options)' with the default store ID (see
2893+ % % EventFilter, Action , Options)' with the default store ID (see
28822894% % {@link khepri_cluster:get_default_store_id/0}).</li>
28832895% % </ul>
28842896% %
28852897% % @see register_trigger/5.
28862898
2887- register_trigger (StoreId , TriggerId , EventFilter , StoredProcPath )
2899+ register_trigger (StoreId , TriggerId , EventFilter , Action )
28882900 when ? IS_KHEPRI_STORE_ID (StoreId ) andalso is_atom (TriggerId ) ->
2889- register_trigger (StoreId , TriggerId , EventFilter , StoredProcPath , #{});
2890- register_trigger (TriggerId , EventFilter , StoredProcPath , Options )
2901+ register_trigger (StoreId , TriggerId , EventFilter , Action , #{});
2902+ register_trigger (TriggerId , EventFilter , Action , Options )
28912903 when is_atom (TriggerId ) andalso is_map (Options ) ->
28922904 StoreId = khepri_cluster :get_default_store_id (),
2893- register_trigger (
2894- StoreId , TriggerId , EventFilter , StoredProcPath , Options ).
2905+ register_trigger (StoreId , TriggerId , EventFilter , Action , Options ).
28952906
2896- -spec register_trigger (
2897- StoreId , TriggerId , EventFilter , StoredProcPath , Options ) ->
2907+ -spec register_trigger (StoreId , TriggerId , EventFilter , Action , Options ) ->
28982908 Ret when
28992909 StoreId :: khepri :store_id (),
29002910 TriggerId :: trigger_id (),
29012911 EventFilter :: khepri_evf :event_filter_or_compat (),
2912+ Action :: StoredProcPath |
2913+ Pid |
2914+ khepri_event_handler :trigger_action (),
29022915 StoredProcPath :: khepri_path :path (),
2916+ Pid :: pid (),
29032917 Options :: command_options () | khepri :trigger_options (),
29042918 Ret :: ok | error ().
29052919% % @doc Registers a trigger.
29062920% %
2907- % % A trigger is based on an event filter. It associates an event with a stored
2908- % % procedure . When an event matching the event filter is emitted, the stored
2909- % % procedure is executed.
2921+ % % A trigger is based on an event filter. It associates an event with an
2922+ % % action . When an event matching the event filter is emitted, the action is
2923+ % % executed.
29102924% %
29112925% % The following event filters are documented by {@link
29122926% % khepri_evf:event_filter()}.
@@ -2927,8 +2941,9 @@ register_trigger(TriggerId, EventFilter, StoredProcPath, Options)
29272941% % EventFilter = "/:stock/:wood/oak".
29282942% % '''
29292943% %
2930- % % The stored procedure is expected to accept a single argument. This argument
2931- % % is a map containing the event properties. Here is an example:
2944+ % % When giving a stored procedure as the action, it is expected to accept a
2945+ % % single argument. This argument is a map containing the event properties.
2946+ % % Here is an example:
29322947% %
29332948% % ```
29342949% % my_stored_procedure(Props) ->
@@ -2938,23 +2953,26 @@ register_trigger(TriggerId, EventFilter, StoredProcPath, Options)
29382953% %
29392954% % The stored procedure is executed on the leader's Erlang node.
29402955% %
2956+ % % When giving a PID as the action, a `#khepri_trigger{}' message is sent to
2957+ % % this process.
2958+ % %
29412959% % It is guaranteed to run at least once. It could be executed multiple times
2942- % % if the Ra leader changes, therefore the stored procedure must be
2943- % % idempotent.
2960+ % % if the Ra leader changes, therefore the action must be idempotent.
29442961% %
29452962% % @param StoreId the name of the Khepri store.
29462963% % @param TriggerId the name of the trigger.
29472964% % @param EventFilter the event filter used to associate an event with a
29482965% % stored procedure.
2949- % % @param StoredProcPath the path to the stored procedure to execute when the
2950- % % corresponding event occurs.
2966+ % % @param Action the path to a stored procedure to execute when the
2967+ % % corresponding event occurs, or PID to send a message to, or a
2968+ % % "wrapped action".
29512969% %
29522970% % @returns `ok' if the trigger was registered, an `{error, Reason}' tuple
29532971% % otherwise.
29542972
2955- register_trigger (StoreId , TriggerId , EventFilter , StoredProcPath , Options ) ->
2973+ register_trigger (StoreId , TriggerId , EventFilter , Action , Options ) ->
29562974 khepri_machine :register_trigger (
2957- StoreId , TriggerId , EventFilter , StoredProcPath , Options ).
2975+ StoreId , TriggerId , EventFilter , Action , Options ).
29582976
29592977% % -------------------------------------------------------------------
29602978% % register_projection().
0 commit comments