[open-ils-commits] r12865 - trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Apr 14 11:37:25 EDT 2009


Author: erickson
Date: 2009-04-14 11:37:23 -0400 (Tue, 14 Apr 2009)
New Revision: 12865

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm
Log:
do the queued ingest dance like vandelay.  create assets after the lineitems are processed so we can begin/commit the transaction after each record

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm	2009-04-14 14:22:17 UTC (rev 12864)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm	2009-04-14 15:37:23 UTC (rev 12865)
@@ -1,4 +1,6 @@
 package OpenILS::Application::Acq::BatchManager;
+use OpenSRF::AppSession;
+use OpenSRF::EX qw/:try/;
 use strict; use warnings;
 
 sub new {
@@ -8,13 +10,16 @@
         lid => 0,
         li => 0,
         copies => 0,
+        bibs => 0,
         progress => 0,
         debits_accrued => 0,
         purchase_order => undef,
         picklist => undef,
         complete => 0,
+        indexed => 0,
         total => 0
     };
+    $self->{ingest_queue} = [];
     $self->{cache} = {};
     return $self;
 }
@@ -78,6 +83,12 @@
     $self->{args}->{progress} += 1;
     return $self;
 }
+sub add_bib {
+    my $self = shift;
+    $self->{args}->{bibs} += 1;
+    $self->{args}->{progress} += 1;
+    return $self;
+}
 sub add_debit {
     my($self, $amount) = @_;
     $self->{args}->{debits_accrued} += $amount;
@@ -95,6 +106,40 @@
     return $self;
 }
 
+sub ingest_ses {
+    my($self, $val) = @_;
+    $self->{ingest_ses} = $val if $val;
+    return $self->{ingest_ses};
+}
+
+sub push_ingest_queue {
+    my($self, $rec_id) = @_;
+
+    $self->ingest_ses(OpenSRF::AppSession->connect('open-ils.ingest'))
+        unless $self->ingest_ses;
+
+    my $req = $self->ingest_ses->request('open-ils.ingest.full.biblio.record', $rec_id);
+
+    push(@{$self->{ingest_queue}}, $req);
+}
+
+sub process_ingest_records {
+    my $self = shift;
+
+    for my $req (@{$self->{ingest_queue}}) {
+
+        try { 
+            $req->gather(1); 
+            $self->{args}->{indexed} += 1;
+            $self->{args}->{progress} += 1;
+        } otherwise {};
+
+        $self->respond;
+    }
+    $self->ingest_ses->disconnect;
+}
+
+
 sub cache {
     my($self, $org, $key, $val) = @_;
     $self->{cache}->{$org} = {} unless $self->{cache}->{org};
@@ -499,8 +544,10 @@
     # -----------------------------------------------------------------
     # first, create the bib record if necessary
     # -----------------------------------------------------------------
+    my $new_bib = 0;
     unless($li->eg_bib_id) {
         create_bib($mgr, $li) or return 0;
+        $new_bib = 1;
     }
 
     my $li_details = $mgr->editor->search_acq_lineitem_detail({lineitem => $li_id}, {idlist=>1});
@@ -526,14 +573,21 @@
         create_copy($mgr, $volume, $lid) or return 0;
     }
 
-    return 1;
+    return { li => $li, new_bib => $new_bib };
 }
 
 sub create_bib {
     my($mgr, $li) = @_;
 
     my $record = OpenILS::Application::Cat::BibCommon->biblio_record_xml_import(
-        $mgr->editor, $li->marc, undef, undef, 1); #$rec->bib_source
+        $mgr->editor, 
+        $li->marc, 
+        undef, 
+        undef, 
+        1, # override tcn collisions
+        1, # no-ingest
+        undef # $rec->bib_source
+    ); 
 
     if($U->event_code($record)) {
         $mgr->editor->event($record);
@@ -542,6 +596,7 @@
     }
 
     $li->eg_bib_id($record->id);
+    $mgr->add_bib;
     return update_lineitem($mgr, $li);
 }
 
@@ -747,6 +802,7 @@
 	$batch->strict_off;
 
 	my $count = 0;
+    my @li_list;
 
 	while(1) {
 
@@ -799,10 +855,7 @@
         import_lineitem_details($mgr, $ordering_agency, $li) or return $mgr->editor->die_event;
         $mgr->respond;
 
-        if($create_assets) {
-            create_lineitem_assets($mgr, $li->id) or return $mgr->editor->die_event;
-        }
-
+        push(@li_list, $li->id);
         $mgr->respond;
 	}
 
@@ -810,6 +863,18 @@
     unlink($filename);
     $cache->delete_cache('vandelay_import_spool_' . $key);
 
+    if($create_assets) {
+        # create the bibs/volumes/copies and ingest the records
+        for my $li_id (@li_list) {
+            $e->xact_begin;
+            my $data = create_lineitem_assets($mgr, $li_id) or return $e->die_event;
+            $e->xact_commit;
+            $mgr->push_ingest_queue($data->{li}->eg_bib_id) if $data->{new_bib};
+            $mgr->respond;
+        }
+        $mgr->process_ingest_records;
+    }
+
     return $mgr->respond_complete;
 }
 
@@ -1021,6 +1086,8 @@
     return $e->die_event unless update_purchase_order($mgr, $po);
 
     $e->commit;
+    $mgr->process_ingest_records;
+
     return $mgr->respond_complete;
 }
 



More information about the open-ils-commits mailing list