Allow action trigger events to be repeated
authorRemington Steed <rjs7@calvin.edu>
Mon, 5 Aug 2013 13:57:04 +0000 (09:57 -0400)
committerMike Rylander <mrylander@gmail.com>
Thu, 12 Sep 2013 17:55:43 +0000 (13:55 -0400)
Currently, there is no way to repeat an event (action/trigger) when a
real-world event occurs more than once for the same target. This only
matters for targets that are persistent (such as a library card)
combined with events that can reoccur (such as expiration, if the
expiration can be removed). To address this, we add a new field to the
action_trigger.event_definition table that sets the amount of time
after which the event is allowed to repeat.

This commit adds the new field to the IDL, database schema and template
files and also provides the simple db upgrade script. It is worth noting
that we chose to base the repeatability on the start_time of the previous
event, which is more predictable than complete_time (which could be null
if the event fails).

Signed-off-by: Remington Steed <rjs7@calvin.edu>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/examples/fm_IDL.xml
Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger.pm
Open-ILS/src/sql/Pg/400.schema.action_trigger.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.action_trigger.event_definition.repeat_delay.sql [new file with mode: 0644]
Open-ILS/src/templates/conify/global/action_trigger/event_definition.tt2

index ba8efaa..861d107 100644 (file)
@@ -1138,6 +1138,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field reporter:label="Granularity" name="granularity"  reporter:datatype="text"/>
                        <field reporter:label="Opt-In User Field" name="usr_field"  reporter:datatype="text"/>
                        <field reporter:label="Opt-In Setting Type" name="opt_in_setting"  reporter:datatype="link"/>
+                       <field reporter:label="Event Repeatability Delay" name="repeat_delay"  reporter:datatype="interval"/>
                        <field reporter:label="Environment Entries" name="env" oils_persist:virtual="true"  reporter:datatype="link"/>
                        <field reporter:label="Parameters" name="params" oils_persist:virtual="true"  reporter:datatype="link"/>
                </fields>
index 24488e8..ed83cba 100644 (file)
@@ -470,6 +470,11 @@ sub create_batch_events {
                 filter => { event_def => $def->id }
             }
         }};
+        if ($def->repeat_delay) {
+            $join->{'join'}{atev}{filter} = { start_time => {
+                '>' => DateTime->now->subtract( seconds => interval_to_seconds($def->repeat_delay) )->strftime( '%F %T%z' )
+            } };
+        }
 
         push @{ $filter->{'-and'} }, { '+atev' => { id => undef } };
 
index bf5e61b..396cd7d 100644 (file)
@@ -183,6 +183,7 @@ CREATE TABLE action_trigger.event_definition (
     cleanup_failure TEXT        REFERENCES action_trigger.cleanup (module) DEFERRABLE INITIALLY DEFERRED,
     delay           INTERVAL    NOT NULL DEFAULT '5 minutes',
     max_delay       INTERVAL,
+    repeat_delay    INTERVAL,
     usr_field       TEXT,
     opt_in_setting  TEXT        REFERENCES config.usr_setting_type (name) DEFERRABLE INITIALLY DEFERRED,
     delay_field     TEXT,                 -- for instance, xact_start on a circ hook ... look for fields on hook.core_type where datatype=timestamp? If not set, delay from now()
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.action_trigger.event_definition.repeat_delay.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.action_trigger.event_definition.repeat_delay.sql
new file mode 100644 (file)
index 0000000..f07a4dc
--- /dev/null
@@ -0,0 +1,8 @@
+BEGIN;
+
+--- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+ALTER TABLE action_trigger.event_definition ADD COLUMN repeat_delay INTERVAL;
+
+COMMIT;
+
index 069a716..5908cc9 100644 (file)
@@ -29,7 +29,7 @@
             <table  jsId="edGrid" 
                     autoHeight='true'
                     dojoType="openils.widget.AutoGrid" 
-                    fieldOrder="['owner', 'name', 'hook', 'active', 'delay', 'delay_field', 'group_field', 'reactor', 'validator']"
+                    fieldOrder="['owner', 'name', 'hook', 'active', 'delay', 'delay_field', 'group_field', 'reactor', 'validator', 'repeat_delay']"
                     suppressFields="['usr_field', 'opt_in_setting', 'max_delay', 'template', 'cleanup_failure', 'cleanup_success']"
                     query="{id: '*'}" 
                     fmClass='atevdef'