forward porting r14769: add max_delay field to optionally pre-invalidate events based...
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 4 Nov 2009 19:36:56 +0000 (19:36 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 4 Nov 2009 19:36:56 +0000 (19:36 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_6_0@14770 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/examples/fm_IDL.xml
Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm
Open-ILS/src/sql/Pg/400.schema.action_trigger.sql

index 0f373d0..5f36e4f 100644 (file)
@@ -647,6 +647,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field reporter:label="Success Cleanup" name="cleanup_success"  reporter:datatype="link"/>
                        <field reporter:label="Failure Cleanup" name="cleanup_failure"  reporter:datatype="link"/>
                        <field reporter:label="Processing Delay" name="delay"  reporter:datatype="interval"/>
+                       <field reporter:label="Max Event Validity Delay" name="max_delay"  reporter:datatype="interval"/>
                        <field reporter:label="Processing Delay Context Field" name="delay_field"  reporter:datatype="text"/>
                        <field reporter:label="Processing Group Context Field" name="group_field"  reporter:datatype="text"/>
                        <field reporter:label="Template" name="template"  reporter:datatype="text"/>
index 73176f1..81fe005 100644 (file)
@@ -359,7 +359,13 @@ sub create_batch_events {
         { hook   => [ keys %hook_hash ], active => 't' },
     );
 
-    my $first_loop = 1;
+    my $orig_filter_and = [];
+    if ($$filter{'-and'}) {
+        for my $f ( @{ $$filter{'-and'} } ) {
+            push @$orig_filter_and, $f;
+        }
+    }
+
     for my $def ( @$defs ) {
 
         my $date = DateTime->now->subtract( seconds => interval_to_seconds($def->delay) );
@@ -381,23 +387,27 @@ sub create_batch_events {
                     ->add( seconds => interval_to_seconds($def->delay) )
                     ->strftime( '%F %T%z' );
         } else {
-            $filter->{ $def->delay_field } = {
-                '<=' => DateTime
-                    ->now
-                    ->subtract( seconds => interval_to_seconds($def->delay) )
-                    ->strftime( '%F %T%z' )
-            };
+            if ($def->max_delay) {
+                my @times = sort {$a <=> $b} interval_to_seconds($def->delay), interval_to_seconds($def->max_delay);
+                $filter->{ $def->delay_field } = {
+                    'between' => [
+                        DateTime->now->subtract( seconds => $times[0] )->strftime( '%F %T%z' ),
+                        DateTime->now->subtract( seconds => $times[1] )->strftime( '%F %T%z' )
+                    ]
+                };
+            } else {
+                $filter->{ $def->delay_field } = {
+                    '<=' => DateTime->now->subtract( seconds => interval_to_seconds($def->delay) )->strftime( '%F %T%z' )
+                };
+            }
         }
 
         my $class = _fm_class_by_hint($hook_hash{$def->hook}->core_type);
 
         # filter where this target has an event (and it's pending, for active hooks)
-        if($first_loop) {
-            $$filter{'-and'} = [] if (!exists($$filter{'-and'}));
-            $first_loop = 0;
-        } else {
-            # remove the pre-existing event check for the previous event def
-            pop @{ $filter->{'-and'} };
+        $$filter{'-and'} = [];
+        for my $f ( @$orig_filter_and ) {
+            push @{ $$filter{'-and'} }, $f;
         }
 
         push @{ $filter->{'-and'} }, {
index 1e6d579..4db2f59 100644 (file)
@@ -110,6 +110,7 @@ CREATE TABLE action_trigger.event_definition (
     cleanup_success TEXT        REFERENCES action_trigger.cleanup (module) DEFERRABLE INITIALLY DEFERRED,
     cleanup_failure TEXT        REFERENCES action_trigger.cleanup (module) DEFERRABLE INITIALLY DEFERRED,
     delay           INTERVAL    NOT NULL DEFAULT '5 minutes',
+    max_delay       INTERVAL,
     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()
     group_field     TEXT,                 -- field from this.hook.core_type to batch event targets together on, fed into reactor a group at a time.
     template        TEXT,                 -- the TT block.  will have an 'environment' hash (or array of hashes, grouped events) built up by validator and collector(s), which can be modified.