From 7f31f9f5281abf8e44b02dfc35f557ebeef25acb Mon Sep 17 00:00:00 2001 From: erickson Date: Tue, 3 Jul 2007 10:56:25 +0000 Subject: [PATCH] gave the offline patron blocked list generator a way to fetch blocked patrons using oils_requestor for speed git-svn-id: svn://svn.open-ils.org/ILS/trunk@7508 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../src/support-scripts/offline-blocked-list.pl | 115 +++++++++++++++------ 1 file changed, 83 insertions(+), 32 deletions(-) diff --git a/Open-ILS/src/support-scripts/offline-blocked-list.pl b/Open-ILS/src/support-scripts/offline-blocked-list.pl index 8933e7a780..5c6f996049 100755 --- a/Open-ILS/src/support-scripts/offline-blocked-list.pl +++ b/Open-ILS/src/support-scripts/offline-blocked-list.pl @@ -1,42 +1,93 @@ #!/usr/bin/perl -use strict; - -use OpenSRF::EX qw(:try); -use OpenSRF::System; -use OpenSRF::AppSession; +use strict; use warnings; my $config = shift || die "Please specify a config file\n"; +my $context = shift || 'opensrf'; -OpenSRF::System->bootstrap_client( config_file => $config ); +my $oils_reqr = '/openils/bin/oils_requestor'; # XXX command line param -my $ses = OpenSRF::AppSession->connect( 'open-ils.storage' ); +if(1) { # XXX command line param -my $lost = $ses->request( 'open-ils.storage.actor.user.lost_barcodes' ); -while (my $resp = $lost->recv ) { - print $resp->content . " L\n"; -} -$lost->finish; - -if(0) { # XXX just too many... arg - my $expired = $ses->request( 'open-ils.storage.actor.user.expired_barcodes' ); - while (my $resp = $expired->recv ) { - print $resp->content . " E\n"; - } - $expired->finish; -} + # ------------------------------------------------------------ + # This sends the method calls to storage via oils_requestor, + # which is able to process the results much faster + # Make this the default for now. + # ------------------------------------------------------------ -my $barred = $ses->request( 'open-ils.storage.actor.user.barred_barcodes' ); -while (my $resp = $barred->recv ) { - print $resp->content . " B\n"; -} -$barred->finish; + use JSON; + use IPC::Open2 qw/open2/; -my $penalized = $ses->request( 'open-ils.storage.actor.user.penalized_barcodes' ); -while (my $resp = $penalized->recv ) { - print $resp->content . " D\n"; -} -$penalized->finish; + sub runmethod { + my $method = shift; + my $flag = shift; + my $command = "echo \"open-ils.storage $method\" | $oils_reqr -f $config -c $context"; + warn "-> $command\n"; + + my ($child_stdout, $child_stdin); + my $pid = open2($child_stdout, $child_stdin, $command); + my $x = 0; + for my $barcode (<$child_stdout>) { + next if $barcode =~ /^oils/o; # hack to chop out the oils_requestor prompt + chomp $barcode; + $barcode = JSON->JSON2perl($barcode); + print "$barcode $flag\n" if $barcode; + } + close($child_stdout); + close($child_stdin); + waitpid($pid, 0); # don't leave any zombies (see ipc::open2) + } + + runmethod('open-ils.storage.actor.user.lost_barcodes', 'L'); + runmethod('open-ils.storage.actor.user.barred_barcodes', 'B'); + runmethod('open-ils.storage.actor.user.penalized_barcodes', 'D'); + # too many, makes the file too large for download + #runmethod('open-ils.storage.actor.user.expired_barcodes', 'E'); + +} else { + + + # ------------------------------------------------------------ + # Uses the traditional opensrf Perl API approach + # ------------------------------------------------------------ -$ses->disconnect; -$ses->finish; + use OpenSRF::EX qw(:try); + use OpenSRF::System; + use OpenSRF::AppSession; + + my $config = shift || die "Please specify a config file\n"; + + OpenSRF::System->bootstrap_client( config_file => $config ); + + my $ses = OpenSRF::AppSession->connect( 'open-ils.storage' ); + + my $lost = $ses->request( 'open-ils.storage.actor.user.lost_barcodes' ); + while (my $resp = $lost->recv ) { + print $resp->content . " L\n"; + } + $lost->finish; + + if(0) { # XXX just too many... arg + my $expired = $ses->request( 'open-ils.storage.actor.user.expired_barcodes' ); + while (my $resp = $expired->recv ) { + print $resp->content . " E\n"; + } + $expired->finish; + } + + my $barred = $ses->request( 'open-ils.storage.actor.user.barred_barcodes' ); + while (my $resp = $barred->recv ) { + print $resp->content . " B\n"; + } + $barred->finish; + + my $penalized = $ses->request( 'open-ils.storage.actor.user.penalized_barcodes' ); + while (my $resp = $penalized->recv ) { + print $resp->content . " D\n"; + } + $penalized->finish; + + $ses->disconnect; + $ses->finish; + +} -- 2.11.0