From df485a39b4b5c18076d3e8a688c4517031cf0e92 Mon Sep 17 00:00:00 2001 From: miker Date: Wed, 4 Nov 2009 19:36:56 +0000 Subject: [PATCH] forward porting r14769: add max_delay field to optionally pre-invalidate events based on a delay window, instead of simply the minimum delay time 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 | 1 + .../src/perlmods/OpenILS/Application/Trigger.pm | 36 ++++++++++++++-------- Open-ILS/src/sql/Pg/400.schema.action_trigger.sql | 1 + 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 0f373d0430..5f36e4fa5a 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -647,6 +647,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm b/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm index 73176f1187..81fe005619 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm @@ -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'} }, { diff --git a/Open-ILS/src/sql/Pg/400.schema.action_trigger.sql b/Open-ILS/src/sql/Pg/400.schema.action_trigger.sql index 1e6d579ef9..4db2f591f7 100644 --- a/Open-ILS/src/sql/Pg/400.schema.action_trigger.sql +++ b/Open-ILS/src/sql/Pg/400.schema.action_trigger.sql @@ -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. -- 2.11.0