use OpenSRF::Utils::Logger qw/$logger/;
use OpenSRF::AppSession;
+use OpenSRF::EX qw/:try/;
use OpenILS::Utils::Cronscript;
require 'oils_header.pl';
use vars qw/$apputils/;
my $extra = {auto_overlay_exact => 1};
$extra->{merge_profile} = $merge_profile if $merge_profile;
+ my $req;
+ my @cleanup_recs;
+
if($import_by_queue) {
+ # import by queue
- $apputils->simplereq(
- 'open-ils.vandelay',
+ $req = $vl_ses->request(
'open-ils.vandelay.bib_queue.import',
$authtoken,
$queue_id,
);
} else {
-
# import explicit record IDs
- $apputils->simplereq(
- 'open-ils.vandelay',
+ $req = $vl_ses->request(
'open-ils.vandelay.bib_record.list.import',
$authtoken,
$rec_ids,
$extra
);
}
+
+ # collect the successfully imported vandelay records
+ while(my $resp = $req->recv) {
+ if($req->failed) {
+ $logger->error("Error importing MARC data: $resp");
+
+ } elsif(my $data = $resp->content) {
+ push(@cleanup_recs, $data->{imported}) unless $data->{err_event};
+ }
+ }
+
+ # clean up the successfully imported vandelay records to prevent queue bloat
+ foreach (@cleanup_recs) {
+
+ try {
+ $apputils->simplereq(
+ 'open-ils.pcrud',
+ 'open-ils.pcrud.delete.vqbr',
+ $authtoken, $_);
+
+ } catch Error with {
+ my $err = shift;
+ $logger->error("Error deleteing queued bib record $_: $err");
+ };
+ }
}
sub process_batch_data {