[open-ils-commits] r14772 - in trunk/Open-ILS: examples src/perlmods/OpenILS/Application src/sql/Pg src/sql/Pg/upgrade (miker)

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Nov 4 14:43:51 EST 2009


Author: miker
Date: 2009-11-04 14:43:46 -0500 (Wed, 04 Nov 2009)
New Revision: 14772

Added:
   trunk/Open-ILS/src/sql/Pg/upgrade/0071.schema.action_trigger.event_definition.max_delay.sql
Modified:
   trunk/Open-ILS/examples/fm_IDL.xml
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm
   trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
   trunk/Open-ILS/src/sql/Pg/400.schema.action_trigger.sql
Log:
forward porting r14769: add max_delay field to optionally pre-invalidate events based on a delay window, instead of simply the minimum delay time

Modified: trunk/Open-ILS/examples/fm_IDL.xml
===================================================================
--- trunk/Open-ILS/examples/fm_IDL.xml	2009-11-04 19:39:49 UTC (rev 14771)
+++ trunk/Open-ILS/examples/fm_IDL.xml	2009-11-04 19:43:46 UTC (rev 14772)
@@ -687,6 +687,7 @@
 			<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"/>

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm	2009-11-04 19:39:49 UTC (rev 14771)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm	2009-11-04 19:43:46 UTC (rev 14772)
@@ -359,7 +359,13 @@
         { 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 @@
                     ->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'} }, {

Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql	2009-11-04 19:39:49 UTC (rev 14771)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql	2009-11-04 19:43:46 UTC (rev 14772)
@@ -51,7 +51,7 @@
     install_date    TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
 );
 
-INSERT INTO config.upgrade_log (version) VALUES ('0070'); -- Scott McKellar
+INSERT INTO config.upgrade_log (version) VALUES ('0071'); -- miker
 
 CREATE TABLE config.bib_source (
 	id		SERIAL	PRIMARY KEY,

Modified: trunk/Open-ILS/src/sql/Pg/400.schema.action_trigger.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/400.schema.action_trigger.sql	2009-11-04 19:39:49 UTC (rev 14771)
+++ trunk/Open-ILS/src/sql/Pg/400.schema.action_trigger.sql	2009-11-04 19:43:46 UTC (rev 14772)
@@ -114,6 +114,7 @@
     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.

Added: trunk/Open-ILS/src/sql/Pg/upgrade/0071.schema.action_trigger.event_definition.max_delay.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0071.schema.action_trigger.event_definition.max_delay.sql	                        (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0071.schema.action_trigger.event_definition.max_delay.sql	2009-11-04 19:43:46 UTC (rev 14772)
@@ -0,0 +1,10 @@
+-- Already exists as far back as 1.6.0.0, so don't use this in version upgrades
+
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0071');
+
+ALTER TABLE action_trigger.event_definition ADD COLUMN max_delay INTERVAL
+
+COMMIT;
+



More information about the open-ils-commits mailing list