[open-ils-commits] r14629 - in trunk/Open-ILS: examples src/support-scripts (miker)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Oct 27 12:57:33 EDT 2009


Author: miker
Date: 2009-10-27 12:57:29 -0400 (Tue, 27 Oct 2009)
New Revision: 14629

Added:
   trunk/Open-ILS/examples/action_trigger_filters.json.example
Modified:
   trunk/Open-ILS/src/support-scripts/action_trigger_runner.pl
Log:
move the hook configuration out to a config file (action_trigger_filters.json.example); default to the list of hooks in that file if none are specified; use try/otherwise instead of eval/$@

Added: trunk/Open-ILS/examples/action_trigger_filters.json.example
===================================================================
--- trunk/Open-ILS/examples/action_trigger_filters.json.example	                        (rev 0)
+++ trunk/Open-ILS/examples/action_trigger_filters.json.example	2009-10-27 16:57:29 UTC (rev 14629)
@@ -0,0 +1,15 @@
+{
+
+'checkout.due' :
+    { 'context_org' => 'circ_lib',
+      'filter'      =>
+            { 'checkin_time'  => undef,
+              '-or'           =>
+                    [ { 'stop_fines'  => ['MAXFINES', 'LONGOVERDUE'] },
+                      { 'stop_fines'  => undef }
+                    ]
+            }
+    }
+
+}
+

Modified: trunk/Open-ILS/src/support-scripts/action_trigger_runner.pl
===================================================================
--- trunk/Open-ILS/src/support-scripts/action_trigger_runner.pl	2009-10-27 14:44:20 UTC (rev 14628)
+++ trunk/Open-ILS/src/support-scripts/action_trigger_runner.pl	2009-10-27 16:57:29 UTC (rev 14629)
@@ -18,14 +18,15 @@
 use Getopt::Long;
 use OpenSRF::AppSession;
 use OpenSRF::Utils::JSON;
+use OpenSRF::EX qw(:try);
 require 'oils_header.pl';
 
 my $opt_lockfile = '/tmp/action-trigger-LOCK';
 my $opt_osrf_config = '/openils/conf/opensrf_core.xml';
+my $opt_custom_filter = '/openils/conf/action_trigger_filters.json';
 my $opt_run_pending = 0;
 my $opt_debug_stdout = 0;
 my $opt_help = 0;
-my $opt_custom_filter;
 my $opt_hooks;
 
 GetOptions(
@@ -33,16 +34,16 @@
     'run-pending' => \$opt_run_pending,
     'hooks=s' => \$opt_hooks,
     'debug-stdout' => \$opt_debug_stdout,
-    'custom-filter=s' => \$opt_custom_filter,
+    'custom-filters=s' => \$opt_custom_filter,
     'lock-file=s' => \$opt_lockfile,
     'help' => \$opt_help,
 );
 
 
 # typical passive hook filters
-my %hook_handlers = (
+my $hook_handlers = {
 
-    # overdue circulations
+    # default overdue circulations
     'checkout.due' => {
         context_org => 'circ_lib',
         filter => {
@@ -53,26 +54,39 @@
             ]
         }
     }
-);
+};
 
+if ($opt_custom_filter) {
+    open FILTERS, $opt_custom_filter;
+    $hook_handlers = OpenSRF::Utils::JSON->JSON2Perl(join('',(<FILTERS>)));
+    close FILTERS;
+}
+
 sub help {
     print <<HELP;
 
 $0 : Create and process action/trigger events
 
-    --osrf-config <config_file>
-        OpenSRF config file
+    --osrf-config=<config_file>
+        OpenSRF core config file.  Defaults to:
+            /openils/conf/opensrf_core.xml
 
+    --custom-filters=<filter_file>
+        File containing a JSON Object which describes any hooks that should
+        use a user-defined filter to find their target objects.  Defaults to:
+            /openils/conf/action_trigger_filters.json
+
     --run-pending
         Run pending action_trigger.event's
 
-    --hooks hook1[,hook2,hook3,...]
-        hooks to generate events for
+    --hooks=hook1[,hook2,hook3,...]
+        Hooks for which events should be generated.  Defaults to the list of
+        hooks defined in the --custom-filters option.
 
     --debug-stdout
         Print server responses to stdout (as JSON) for debugging
 
-    --lock-file <file_name>
+    --lock-file=<file_name>
         Lock file
 
     --help
@@ -80,7 +94,8 @@
 
     Examples:
 
-        # To run all pending events.  This is what you tell CRON to run at regular intervals
+        # To run all pending events.  This is what you tell CRON to run at
+        # regular intervals
         perl $0 --osrf-config /openils/conf/opensrf_core.xml --run-pending
 
         # To batch create all "checkout.due" events
@@ -93,18 +108,16 @@
 # create events for the specified hooks using the configured filters and context orgs
 sub process_hooks {
 
-    my @hooks = ($opt_hooks) ? split(',', $opt_hooks) : ();
+    my @hooks = ($opt_hooks) ? split(',', $opt_hooks) : keys(%$hook_handlers);
     my $ses = OpenSRF::AppSession->create('open-ils.trigger');
 
     for my $hook (@hooks) {
     
-        my $config = $hook_handlers{$hook} or next;
+        my $config = $$hook_handlers{$hook} or next;
         my $method = 'open-ils.trigger.passive.event.autocreate.batch';
         $method =~ s/passive/active/ if $config->{active};
         
-        my $filter = ($opt_custom_filter) ? OpenSRF::Utils::JSON->JSON2Perl($opt_custom_filter) : $config->{filter};
-    
-        my $req = $ses->request($method, $hook, $config->{context_org}, $filter);
+        my $req = $ses->request($method, $hook, $config->{context_org}, $config->{filter});
         while(my $resp = $req->recv(timeout => 1800)) {
             if($opt_debug_stdout) {
                 print OpenSRF::Utils::JSON->perl2JSON($resp->content) . "\n";
@@ -133,14 +146,15 @@
 print F $$;
 close F;
 
-eval {
+try {
     osrf_connect($opt_osrf_config);
     process_hooks();
     run_pending();
+} otherwise {
+    my $e = shift;
+    warn "$e\n";
 };
 
-warn "$@\n" if $@;
-
 unlink $opt_lockfile;
 
 



More information about the open-ils-commits mailing list