From fb19e77aa6266c67aed2245a94a32b79ca1a7e8a Mon Sep 17 00:00:00 2001 From: miker Date: Thu, 5 Nov 2009 19:27:04 +0000 Subject: [PATCH] Patch from Lebbeous Fogle-Weekley to add arbitrary event runtime grouping (granularity) to action-trigger events; also includes support for specifying granularity to action_trigger_runner.pl and the server-side batch events git-svn-id: svn://svn.open-ils.org/ILS/trunk@14790 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/examples/fm_IDL.xml | 3 +++ .../src/perlmods/OpenILS/Application/Trigger.pm | 22 ++++++++++++++++------ Open-ILS/src/sql/Pg/400.schema.action_trigger.sql | 4 +++- ...ction_trigger.granularity_and_async_results.sql | 8 ++++++++ .../src/support-scripts/action_trigger_runner.pl | 9 +++++++-- 5 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/0072.schema.action_trigger.granularity_and_async_results.sql diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 979d12158c..b70c4672d8 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -692,6 +692,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + @@ -728,12 +729,14 @@ 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 fa6f230c80..15797aeda1 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm @@ -339,6 +339,7 @@ sub create_batch_events { my $key = shift; my $location_field = shift; # where to look for event_def.owner filtering ... circ_lib, for instance, where hook.core_type = circ my $filter = shift || {}; + my $granularity = shift; my $active = ($self->api_name =~ /active/o) ? 1 : 0; if ($active && !keys(%$filter)) { @@ -433,6 +434,7 @@ sub create_batch_events { $event->target( $o_id ); $event->event_def( $def->id ); $event->run_time( $run_time ); + $event->granularity($granularity) if (defined $granularity); $editor->create_action_trigger_event( $event ); @@ -460,7 +462,6 @@ __PACKAGE__->register_method( argc => 2 ); - sub fire_single_event { my $self = shift; my $client = shift; @@ -520,12 +521,20 @@ __PACKAGE__->register_method( sub pending_events { my $self = shift; my $client = shift; + my $granularity = shift; my $editor = new_editor(); + my $query = [{ state => 'pending', run_time => {'<' => 'now'} }, { order_by => { atev => [ qw/run_time add_time/] } }]; + + if (defined $granularity) { + $query->[0]->{'-or'} = [ {granularity => $granularity}, {granularity => undef} ]; + } else { + $query->[0]->{granularity} = undef; + } + return $editor->search_action_trigger_event( - [{ state => 'pending', run_time => {'<' => 'now'} }, { order_by => { atev => [ qw/run_time add_time/] } }], - { idlist=> 1, timeout => 1800 } + $query, { idlist=> 1, timeout => 1800 } ); } __PACKAGE__->register_method( @@ -534,12 +543,12 @@ __PACKAGE__->register_method( api_level=> 1 ); - sub grouped_events { my $self = shift; my $client = shift; + my $granularity = shift; - my ($events) = $self->method_lookup('open-ils.trigger.event.find_pending')->run(); + my ($events) = $self->method_lookup('open-ils.trigger.event.find_pending')->run($granularity); my %groups = ( '*' => [] ); @@ -598,8 +607,9 @@ __PACKAGE__->register_method( sub run_all_events { my $self = shift; my $client = shift; + my $granularity = shift; - my ($groups) = $self->method_lookup('open-ils.trigger.event.find_pending_by_group')->run(); + my ($groups) = $self->method_lookup('open-ils.trigger.event.find_pending_by_group')->run($granularity); for my $def ( %$groups ) { if ($def eq '*') { 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 31ec7df55b..a225a51d01 100644 --- a/Open-ILS/src/sql/Pg/400.schema.action_trigger.sql +++ b/Open-ILS/src/sql/Pg/400.schema.action_trigger.sql @@ -118,6 +118,7 @@ CREATE TABLE action_trigger.event_definition ( 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. + granularity TEXT, -- could specify a batch which is the only time these events should actually run CONSTRAINT ev_def_owner_hook_val_react_clean_delay_once UNIQUE (owner, hook, validator, reactor, delay, delay_field), CONSTRAINT ev_def_name_owner_once UNIQUE (owner, name) ); @@ -153,7 +154,8 @@ CREATE TABLE action_trigger.event ( update_process INT, state TEXT NOT NULL DEFAULT 'pending' CHECK (state IN ('pending','invalid','found','collecting','collected','validating','valid','reacting','reacted','cleaning','complete','error')), template_output BIGINT REFERENCES action_trigger.event_output (id), - error_output BIGINT REFERENCES action_trigger.event_output (id) + error_output BIGINT REFERENCES action_trigger.event_output (id), + async_output BIGINT REFERENCES action_trigger.event_output (id) ); CREATE TABLE action_trigger.event_params ( diff --git a/Open-ILS/src/sql/Pg/upgrade/0072.schema.action_trigger.granularity_and_async_results.sql b/Open-ILS/src/sql/Pg/upgrade/0072.schema.action_trigger.granularity_and_async_results.sql new file mode 100644 index 0000000000..dffaf60cd1 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0072.schema.action_trigger.granularity_and_async_results.sql @@ -0,0 +1,8 @@ +BEGIN; + +INSERT INTO config.upgrade_log (version) VALUES ('0072'); + +ALTER TABLE action_trigger.event_definition ADD COLUMN granularity TEXT; +ALTER TABLE action_trigger.event ADD COLUMN async_output BIGINT REFERENCES action_trigger.event_output (id); + +COMMIT; diff --git a/Open-ILS/src/support-scripts/action_trigger_runner.pl b/Open-ILS/src/support-scripts/action_trigger_runner.pl index 3b5ac6219b..9297da1966 100755 --- a/Open-ILS/src/support-scripts/action_trigger_runner.pl +++ b/Open-ILS/src/support-scripts/action_trigger_runner.pl @@ -29,11 +29,13 @@ my $opt_debug_stdout = 0; my $opt_help = 0; my $opt_hooks; my $opt_process_hooks = 0; +my $opt_granularity = undef; GetOptions( 'osrf-config=s' => \$opt_osrf_config, 'run-pending' => \$opt_run_pending, 'hooks=s' => \$opt_hooks, + 'hooks=s' => \$opt_granularity, 'process-hooks' => \$opt_process_hooks, 'debug-stdout' => \$opt_debug_stdout, 'custom-filters=s' => \$opt_custom_filter, @@ -88,6 +90,9 @@ $0 : Create and process action/trigger events Define which hooks to create events for. If none are defined, it defaults to the list of hooks defined in the --custom-filters option. + --granularity=label + Run events with {label} granularity setting, or no granularity setting + --debug-stdout Print server responses to stdout (as JSON) for debugging @@ -123,7 +128,7 @@ sub process_hooks { my $method = 'open-ils.trigger.passive.event.autocreate.batch'; $method =~ s/passive/active/ if $config->{active}; - my $req = $ses->request($method, $hook, $config->{context_org}, $config->{filter}); + my $req = $ses->request($method, $hook, $config->{context_org}, $config->{filter}, $opt_granularity); while(my $resp = $req->recv(timeout => 1800)) { if($opt_debug_stdout) { print OpenSRF::Utils::JSON->perl2JSON($resp->content) . "\n"; @@ -135,7 +140,7 @@ sub process_hooks { sub run_pending { return unless $opt_run_pending; my $ses = OpenSRF::AppSession->create('open-ils.trigger'); - my $req = $ses->request('open-ils.trigger.event.run_all_pending'); + my $req = $ses->request('open-ils.trigger.event.run_all_pending' => $opt_granularity); while(my $resp = $req->recv(timeout => 600)) { if($opt_debug_stdout) { print OpenSRF::Utils::JSON->perl2JSON($resp->content) . "\n"; -- 2.11.0