[open-ils-commits] r15889 - trunk/Open-ILS/src/support-scripts (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Mar 17 20:04:01 EDT 2010


Author: erickson
Date: 2010-03-17 20:04:00 -0400 (Wed, 17 Mar 2010)
New Revision: 15889

Modified:
   trunk/Open-ILS/src/support-scripts/marc_stream_importer.pl
Log:
Mid-refactor move data processing into sub

Modified: trunk/Open-ILS/src/support-scripts/marc_stream_importer.pl
===================================================================
--- trunk/Open-ILS/src/support-scripts/marc_stream_importer.pl	2010-03-18 00:04:00 UTC (rev 15888)
+++ trunk/Open-ILS/src/support-scripts/marc_stream_importer.pl	2010-03-18 00:04:00 UTC (rev 15889)
@@ -77,6 +77,7 @@
 use MARC::File::XML;
 use MARC::File::USMARC;
 use File::Basename qw/fileparse/;
+use Getopt::Long;
 
 use OpenSRF::Utils::Logger qw/$logger/;
 use OpenILS::Utils::Cronscript;
@@ -112,24 +113,17 @@
 print warning();
 # $0 = 'Evergreen MARC Stream Listener';
 
-sub process_request {
-    my $self = shift;
-    my $socket = $self->{server}->{client};
-    my $data = '';
-    my $buf;
+sub xml_import {
+    return $apputils->simplereq(
+        'open-ils.cat', 
+        'open-ils.cat.biblio.record.xml.import',
+        @_
+    );
+}
 
-    # Reading <STDIN> blocks until the client is closed.  Instead of waiting 
-    # for that, give each inbound record $wait_time seconds to fully arrive
-    # and pull the data directly from the socket
-    eval {
-        local $SIG{ALRM} = sub { die "alarm\n" }; 
-        do {
-            alarm $wait_time;
-            last unless $socket->sysread($buf, $bufsize);
-            $data .= $buf;
-        } while(1);
-        alarm 0;
-    };
+sub process_batch_data {
+    my $data = shift or $logger->error("process_batch_data called without any data");
+    $data or return;
 
     my $handle;
     open $handle, '<', \$data; 
@@ -151,40 +145,49 @@
 
         last unless $rec;
 
-        my $resp = $apputils->simplereq(
-            'open-ils.cat', 
-            'open-ils.cat.biblio.record.xml.import',
-            $authtoken, 
-            $rec->as_xml_record, 
-            $bib_source
-        );
+        my $resp = xml_import($authtoken, $rec->as_xml_record, $bib_source);
 
         # has the session timed out?
-        if(oils_event_equals($resp, 'NO_SESSION')) {
-            set_auth_token();
-            my $resp = $apputils->simplereq(
-                'open-ils.cat', 
-                'open-ils.cat.biblio.record.xml.import',
-                $authtoken, 
-                $rec->as_xml_record, 
-                $bib_source
-            );
-            oils_event_die($resp);
-        } else {
-            oils_event_die($resp);
+        if (oils_event_equals($resp, 'NO_SESSION')) {
+            new_auth_token();
+            $resp = xml_import($authtoken, $rec->as_xml_record, $bib_source);   # try again w/ new token
         }
+        oils_event_die($resp);
     }
+    return $index;
 }
 
+sub process_request {
+    my $self = shift;
+    my $socket = $self->{server}->{client};
+    my $data = '';
+    my $buf;
 
+    # Reading <STDIN> blocks until the client is closed.  Instead of waiting 
+    # for that, give each inbound record $wait_time seconds to fully arrive
+    # and pull the data directly from the socket
+    eval {
+        local $SIG{ALRM} = sub { die "alarm\n" }; 
+        do {
+            alarm $wait_time;
+            last unless $socket->sysread($buf, $bufsize);
+            $data .= $buf;
+        } while(1);
+        alarm 0;
+    };
+    process_batch_data($data);
+}
+
+
 # the authtoken will timeout after the configured inactivity period.
 # When that happens, get a new one.
-sub set_auth_token {
+sub new_auth_token {
     $authtoken = oils_login($oils_username, $oils_password, 'staff') 
         or die "Unable to login to Evergreen";
+    return $authtoken;
 }
 
 osrf_connect($osrf_config);
-set_auth_token();
+new_auth_token();
 __PACKAGE__->run();
 



More information about the open-ils-commits mailing list