acq order reader; continuing
authorBill Erickson <berick@esilibrary.com>
Mon, 23 Jul 2012 17:50:09 +0000 (13:50 -0400)
committerBill Erickson <berick@esilibrary.com>
Mon, 23 Jul 2012 17:50:09 +0000 (13:50 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/examples/opensrf.xml.example
Open-ILS/src/support-scripts/acq_order_reader.pl

index 05891ae..508fe88 100644 (file)
@@ -277,7 +277,7 @@ vim:et:ts=4:sw=4:
 
             <!-- any files found in the shared subdir must be inspected
                  (e.g. file name prefix) to determine the provider. -->
-            <shared_subdir>ALL</shared_subdir>
+            <shared_subdir>ALL</shared_subdir><!-- SUPPORT PENDING -->
 
             <!-- providers that don't provide a mechanism to inspect the file
                  have to push their files to provider-specific locations -->
index da72226..ba0e2aa 100755 (executable)
@@ -53,6 +53,9 @@ my %defaults = (
     'poll-interval=i' => 10
 );
 
+# -----------------------------------------------------
+# Command-line args reading / munging
+# -----------------------------------------------------
 $OpenILS::Utils::Cronscript::debug=1 if $debug;
 $Getopt::Long::debug=1 if $debug > 1;
 my $o = OpenILS::Utils::Cronscript->new(\%defaults);
@@ -105,7 +108,11 @@ if ($debug) {
     }
 }
 
-print Dumper($real_opts);
+$debug and print Dumper($real_opts);
+
+# -----------------------------------------------------
+# subs
+# -----------------------------------------------------
 
 # log in
 sub new_auth_token {
@@ -159,16 +166,19 @@ sub push_file_to_acq {
     # TODO: delete tmp queue?
 }
 
+my %org_cache;
 sub org_from_sn {
     my $sn = shift;
+    return $org_cache{$sn} if $org_cache{$sn};
     my $org = $editor->search_actor_org_unit({shortname => $sn})->[0];
     if (!$org) {
         warn "No such org unit in acq_order_reader config: '$sn'\n";
         return undef;
     }
-    return $org;
+    return $org_cache{$sn} = $org;
 }
 
+# translate config info into a request arguments structure
 sub args_from_provider_conf {
     my $conf = shift;
     my %args;
@@ -211,7 +221,7 @@ sub args_from_provider_conf {
         $args{vandelay}->{$opt} = $vconf->{$opt} 
     }
 
-    # boolean options
+    # bool options
     for my $opt (
         qw/
             create_assets
@@ -316,14 +326,16 @@ while (1) {
     clear_auth_token();
 
     $logger->info("acq-or: loop processed $processed files");
-    $debug and print "Sleeping for $poll_interval seconds...\n";
 
     $SIG{INT} = sub { 
         print "Cleaning up...\n";
         exit; # allows lockfile cleanup
     };
 
-    sleep $poll_interval;
+    # processing takes time.  If we processed any records
+    # during the current iteration, immediately check again
+    # for more work.  Otherwise, wait $poll_interval seconds
+    sleep $poll_interval if $processed == 0;
 }
 
 __END__