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

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Nov 5 14:27:08 EST 2009


Author: miker
Date: 2009-11-05 14:27:04 -0500 (Thu, 05 Nov 2009)
New Revision: 14790

Added:
   trunk/Open-ILS/src/sql/Pg/upgrade/0072.schema.action_trigger.granularity_and_async_results.sql
Modified:
   trunk/Open-ILS/examples/fm_IDL.xml
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm
   trunk/Open-ILS/src/sql/Pg/400.schema.action_trigger.sql
   trunk/Open-ILS/src/support-scripts/action_trigger_runner.pl
Log:
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

Modified: trunk/Open-ILS/examples/fm_IDL.xml
===================================================================
--- trunk/Open-ILS/examples/fm_IDL.xml	2009-11-05 18:53:17 UTC (rev 14789)
+++ trunk/Open-ILS/examples/fm_IDL.xml	2009-11-05 19:27:04 UTC (rev 14790)
@@ -692,6 +692,7 @@
 			<field reporter:label="Processing Group Context Field" name="group_field"  reporter:datatype="text"/>
 			<field reporter:label="Template" name="template"  reporter:datatype="text"/>
 			<field reporter:label="Name" name="name"  reporter:datatype="text"/>
+			<field reporter:label="Granularity" name="granularity"  reporter:datatype="text"/>
 			<field reporter:label="Environmet Entries" name="env" oils_persist:virtual="true"  reporter:datatype="link"/>
 			<field reporter:label="Parameters" name="params" oils_persist:virtual="true"  reporter:datatype="link"/>
 		</fields>
@@ -728,12 +729,14 @@
 			<field reporter:label="State" name="state" reporter:datatype="text"/>
 			<field reporter:label="Template Output" name="template_output" reporter:datatype="link"/>
 			<field reporter:label="Error Output" name="error_output" reporter:datatype="text"/>
+			<field reporter:label="Asynchronous Output" name="async_output" reporter:datatype="link"/>
 			<field reporter:label="Update Process" name="update_process" reporter:datatype="int"/>
 		</fields>
 		<links>
 			<link field="event_def" reltype="has_a" key="id" map="" class="atevdef"/>
 			<link field="template_output" reltype="has_a" key="id" map="" class="ateo"/>
 			<link field="error_output" reltype="has_a" key="id" map="" class="ateo"/>
+			<link field="async_output" reltype="has_a" key="id" map="" class="ateo"/>
 		</links>
 	</class>
 

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm	2009-11-05 18:53:17 UTC (rev 14789)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm	2009-11-05 19:27:04 UTC (rev 14790)
@@ -339,6 +339,7 @@
     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 @@
             $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 @@
     argc     => 2
 );
 
-
 sub fire_single_event {
     my $self = shift;
     my $client = shift;
@@ -520,12 +521,20 @@
 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 @@
     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 @@
 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 '*') {

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-05 18:53:17 UTC (rev 14789)
+++ trunk/Open-ILS/src/sql/Pg/400.schema.action_trigger.sql	2009-11-05 19:27:04 UTC (rev 14790)
@@ -118,6 +118,7 @@
     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 @@
     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 (

Added: trunk/Open-ILS/src/sql/Pg/upgrade/0072.schema.action_trigger.granularity_and_async_results.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0072.schema.action_trigger.granularity_and_async_results.sql	                        (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0072.schema.action_trigger.granularity_and_async_results.sql	2009-11-05 19:27:04 UTC (rev 14790)
@@ -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;

Modified: trunk/Open-ILS/src/support-scripts/action_trigger_runner.pl
===================================================================
--- trunk/Open-ILS/src/support-scripts/action_trigger_runner.pl	2009-11-05 18:53:17 UTC (rev 14789)
+++ trunk/Open-ILS/src/support-scripts/action_trigger_runner.pl	2009-11-05 19:27:04 UTC (rev 14790)
@@ -29,11 +29,13 @@
 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 @@
         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 @@
         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 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";



More information about the open-ils-commits mailing list