]> git.evergreen-ils.org Git - Evergreen.git/blob - docs/modules/admin/pages/actiontriggers.adoc
docs: Angular Acq Sprint 0 Tools and Infrastructure
[Evergreen.git] / docs / modules / admin / pages / actiontriggers.adoc
1 = Notifications / Action Triggers =
2 :toc:
3
4
5 == Introduction ==
6
7 indexterm:[action triggers, event definitions, notifications]
8
9 Action Triggers give administrators the ability to set up actions for
10 specific events. They are useful for notification events such as hold notifications.
11
12 To access the Action Triggers module, select *Administration* -> *Local Administration* ->  *Notifications / Action triggers*.
13
14 [NOTE]
15 ==========
16 You must have Local Administrator permissions to access the Action Triggers module.
17 ==========
18
19 You will notice four tabs on this page: <<event_definitions, Event Definitions>>, <<hooks, Hooks>>, <<reactors, Reactors>> and <<validators, Validators>>.
20
21
22 [#event_definitions]
23
24 == Event Definitions ==
25
26 Event Definitions is the main tab and contains the key fields when working with action triggers. These fields include:
27
28 === Table 1: Action Trigger Event Definitions ===
29
30
31 |==============================================
32 |*Field*                         |*Description*
33 | Owning Library                 |The shortname of the library for which the action / trigger / hook is defined.
34 | Name                           |The name of the trigger event, that links to a trigger event environment containing a set of fields that will be returned to the <<validators, Validators>> and/or <<reactors, Reactors>> for processing.
35 | <<hooks, Hook>>                |The name of the trigger for the trigger event. The underlying action_trigger.hook table defines the Fieldmapper class in the core_type column off of which the rest of the field definitions ``hang''.
36 | Enabled                        |Sets the given trigger as enabled or disabled. This must be set to enabled for the Action trigger to run.
37 | Processing Delay               |Defines how long after a given trigger / hook event has occurred before the associated action (``Reactor'') will be taken.
38 | Processing Delay Context Field |Defines the field associated with the event on which the processing delay is calculated. For example, the processing delay context field on the hold.capture hook (which has a core_type of ahr) is _capture_time_.
39 | Processing Group Context Field |Used to batch actions based on its associated group.
40 | <<reactors, Reactor>>          |Links the action trigger to the Reactor.
41 | <<validators, Validator>>      |The subroutines receive the trigger environment as an argument (see the linked Name for the environment definition) and returns either _1_ if the validator is _true_ or _0_ if the validator returns _false_.
42 | Event Repeatability Delay      |Allows events to be repeated after this delay interval.
43 | Failure Cleanup                |After an event is reacted to and if there is a failure a cleanup module can be run to clean up after the event.
44 | Granularity                    |Used to group events by how often they should be run. Options are Hourly, Daily, Weekly, Monthly, Yearly, but you may also create new values.
45 | Max Event Validity Delay       |Allows events to have a range of time that they are valid.  This value works with the *Processing Delay* to define a time range.
46 | Message Library Path           |Defines the org_unit object for a Patron Message Center message.
47 | Message Template               |A Template Toolkit template that can be used to generate output for a Patron Message Center message.  The output may or may not be used by the reactor or another external process.
48 | Message Title                  |The title that will display on a Patron Message Center message.
49 | Message User Path              |Defines the user object for a Patron Message Center message.
50 | Opt-In Settings Type           |Choose which User Setting Type will decide if this event will be valid for a certain user.  Use this to allow users to Opt-In or Opt-Out of certain events.
51 | Opt-In User Field              |Set to the name of the field in the selected hook's core type that will link the core type to the actor.usr table. 
52 | Success Cleanup                |After an event is reacted to successfully a cleanup module can be run to clean up after the event.
53 | Template                       |A Template Toolkit template that can be used to generate output.  The output may or may not be used by the reactor or another external process.
54 |==============================================
55
56
57 == Creating Action Triggers ==
58
59 . From the top menu, select *Administration* -> *Local Administration* ->  *Notifications / Action triggers*.
60 . Click on the _New_ button.
61 +
62 image::media/new_event_def.png[New Event Definition]
63 +
64 . Select an _Owning Library_.
65 . Create a unique _Name_ for your new action trigger.
66 . Select the _Hook_.
67 . Check the _Enabled_ check box.
68 . Set the _Processing Delay_ in the appropriate format. E.g. _7 days_ to run 7 days from the trigger event or _00:01:00_ to run 1 hour after the _Processing Delay Context Field_.
69 . Set the _Processing Delay Context Field_ and _Processing Group Context Field_.
70 . Select the _Reactor_ and _Validator_.
71 . Set the _Event Repeatability Delay_.
72 . Select the _Failure Cleanup_ and _Granularity_.
73 . Set the _Max Event Validity Delay_.
74 +
75 image::media/event_def_details.png[Event Definition Details]
76 +
77 . If you wish to send a User Message through the Message Center, set a _Message Library Path_.  Enter text in the _Message Template_.  Enter a title for this message in _Message Title_, and set a value in _Message User Path_.
78 . Select the _Opt-In Setting Type_.
79 . Set the _Opt-In User Field_.
80 . Select the _Success Cleanup_.
81 +
82 image::media/event_def_details_2.png[Event Definition Details]
83 +
84 . Enter text in the _Template_ text box if required. These are for email messages. Here is a sample template for sending 90 day overdue notices:
85
86
87   [%- USE date -%]
88   [%- user = target.0.usr -%]
89   To: [%- params.recipient_email || user.email %]
90   From: [%- helpers.get_org_setting(target.home_ou.id, 'org.bounced_emails') || lib.email || params.sender_email || default_sender %]
91   Subject: Overdue Items Marked Lost
92   Auto-Submitted: auto-generated
93
94   Dear [% user.family_name %], [% user.first_given_name %]
95   The following items are 90 days overdue and have been marked LOST.
96   [%- params.recipient_email || user.email %][%- params.sender_email || default_sender %]
97   [% FOR circ IN target %]
98     Title: [% circ.target_copy.call_number.record.simple_record.title %]
99     Barcode: [% circ.target_copy.barcode %]
100     Due: [% date.format(helpers.format_date(circ.due_date), '%Y-%m-%d') %]
101     Item Cost: [% helpers.get_copy_price(circ.target_copy) %]
102     Total Owed For Transaction: [% circ.billable_transaction.summary.total_owed %]
103     Library: [% circ.circ_lib.name %]
104   [% END %]
105
106   [% FOR circ IN target %]
107     Title: [% circ.target_copy.call_number.record.simple_record.title %]
108     Barcode: [% circ.target_copy.barcode %]
109     Due: [% date.format(helpers.format_date(circ.due_date), '%Y-%m-%d') %]
110     Item Cost: [% helpers.get_copy_price(circ.target_copy) %]
111     Total Owed For Transaction: [% circ.billable_transaction.summary.total_owed %]
112     Library: [% circ.circ_lib.name %]
113   [% END %]
114
115 . Once you are satisfied with your new event trigger, click the _Save_ button located at the bottom of the form.
116
117
118 [TIP]
119 =========
120 A quick and easy way to create new action triggers is to clone an existing action trigger.
121 =========
122
123 === Cloning Existing Action Triggers ===
124
125 . Check the check box next to the action trigger you wish to clone.
126 . Click _Clone Selected_ on the top left of the page.
127 . An editing window will open. Notice that the fields will be populated with content from the cloned action trigger. Edit as necessary and give the new action trigger a unique Name.
128 . Click _Save_.
129
130 === Editing Action Triggers ===
131
132 . Double-click on the action trigger you wish to edit.
133 . The edit screen will appear. When you are finished editing, click _Save_ at the bottom of the form. Or click _Cancel_ to exit the screen without saving.
134
135 [NOTE]
136 ============
137 Before deleting an action trigger, you should consider disabling it through the editing form. This way you can keep it for future use or cloning.
138 ============
139
140 === Deleting Action Triggers ===
141
142 . Check the check box next to the action trigger you wish to delete
143 . Click _Delete Selected_ on the top-right of the page.
144
145 === Testing Action Triggers ===
146
147 . Go to the list of action triggers.
148 . Click on the blue link text for the action trigger you'd like to test.
149 +
150 image::media/test_event_def.png[Blue Link Text]
151 +
152 . Go to the Test tab.
153 . If there is a test available, fill in the required information.
154 . View the output of the test.
155
156 image::media/test_event_def_output.png[Test Output]
157
158 WARNING: If you are testing an email or SMS notification, use a test account and email as an example. Using the Test feature will actually result in the notification being sent if configured correctly.  Similarly, use a test item or barcode when testing a circulation-based event like Mark Lost since the test will mark the item as lost.
159
160 [#hooks]
161
162 === Hooks ===
163
164 Hooks define the Fieldmapper class in the core_type column off of which the rest of the field definitions ``hang''.
165
166
167 ==== Table 2. Hooks ====
168
169
170 |=======================
171 | *Field*        | *Description*
172 | Hook Key       | A unique name given to the hook.
173 | Core Type      | Used to link the action trigger to the IDL class in fm_IDL.xml
174 | Description    | Text to describe the purpose of the hook.
175 | Passive        | Indicates whether or not an event is created by direct user action or is circumstantial.
176 |=======================
177
178 You may also create, edit and delete Hooks but the Core Type must refer to an IDL class in the fm_IDL.xml file.
179
180
181 [#reactors]
182
183 === Reactors ===
184
185 Reactors link the trigger definition to the action to be carried out.
186
187 ==== Table 3. Action Trigger Reactors ====
188
189
190 |=======================
191 | Field        | Description
192 | Module Name  | The name of the Module to run if the action trigger is validated. It must be defined as a subroutine in `/openils/lib/perl5/OpenILS/Application/Trigger/Reactor.pm` or as a module in `/openils/lib/perl5/OpenILS/Application/Trigger/Reactor/*.pm`.
193 | Description  | Description of the Action to be carried out.
194 |=======================
195
196 You may also create, edit and delete Reactors. Just remember that there must be an associated subroutine or module in the Reactor Perl module.
197
198
199 [#validators]
200
201 === Validators ===
202
203 Validators set the validation test to be preformed to determine whether the action trigger is executed.
204
205 ==== Table 4. Action Trigger Validators ====
206
207
208 |=======================
209 | Field         | Description
210 | Module Name   | The name of the subroutine in `/openils/lib/perl5/OpenILS/Application/Trigger/Reactor.pm` to validate the action trigger.
211 | Description   | Description of validation test to run.
212 |=======================
213
214 You may also create, edit and delete Validators. Just remember that their must be an associated subroutine in the Reactor.pm Perl module.
215
216 [#processing_action_triggers]
217 == Processing Action Triggers ==
218
219 To run action triggers, an Evergreen administrator will need to run the trigger processing script. This should be set up as a cron job to run periodically. To run the script, use this command:
220
221 ----
222 /openils/bin/action_trigger_runner.pl --process-hooks --run-pending
223 ----
224
225 You have several options when running the script:
226
227 * --run-pending: Run pending events to send emails or take other actions as
228 specified by the reactor in the event definition.
229
230 * --process-hooks: Create hook events
231
232 * --osrf-config=[config_file]: OpenSRF core config file. Defaults to:
233 /openils/conf/opensrf_core.xml
234
235 * --custom-filters=[filter_file]: File containing a JSON Object which describes any hooks
236 that should use a user-defined filter to find their target objects. Defaults to:
237 /openils/conf/action_trigger_filters.json
238
239 * --max-sleep=[seconds]: When in process-hooks mode, wait up to [seconds] for the lock file to go
240 away. Defaults to 3600 (1 hour).
241
242 * --hooks=hook1[,hook2,hook3,...]: Define which hooks to create events for. If none are defined, it
243 defaults to the list of hooks defined in the --custom-filters option.
244 Requires --process-hooks.
245
246 * --granularity=[label]: Limit creating events and running pending events to
247 those only with [label] granularity setting.
248
249 * --debug-stdout: Print server responses to STDOUT (as JSON) for debugging.
250
251 * --lock-file=[file_name]: Sets the lock file for the process.
252
253 * --verbose: Show details of script processing.
254
255 * --help: Show help information.
256
257 Examples:
258
259 * Run all pending events that have no granularity set. This is what you tell
260 CRON to run at regular intervals.
261 +
262 ----
263 perl action_trigger_runner.pl --run-pending
264 ----
265
266 * Batch create all "checkout.due" events
267 +
268 ----
269 perl action_trigger_runner.pl --hooks=checkout.due --process-hooks
270 ----
271
272 * Batch create all events for a specific granularity and to send notices for all
273 pending events with that same granularity.
274 +
275 ----
276 perl action_trigger_runner.pl --run-pending --granularity=Hourly --process-hooks
277 ----
278