[open-ils-commits] r7508 - trunk/Open-ILS/src/support-scripts
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Jul 3 07:00:00 EDT 2007
Author: erickson
Date: 2007-07-03 06:56:25 -0400 (Tue, 03 Jul 2007)
New Revision: 7508
Modified:
trunk/Open-ILS/src/support-scripts/offline-blocked-list.pl
Log:
gave the offline patron blocked list generator a way to fetch blocked patrons using oils_requestor for speed
Modified: trunk/Open-ILS/src/support-scripts/offline-blocked-list.pl
===================================================================
--- trunk/Open-ILS/src/support-scripts/offline-blocked-list.pl 2007-07-02 23:34:34 UTC (rev 7507)
+++ trunk/Open-ILS/src/support-scripts/offline-blocked-list.pl 2007-07-03 10:56:25 UTC (rev 7508)
@@ -1,42 +1,93 @@
#!/usr/bin/perl
-use strict;
+use strict; use warnings;
-use OpenSRF::EX qw(:try);
-use OpenSRF::System;
-use OpenSRF::AppSession;
-
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;
+ # ------------------------------------------------------------
+ # 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.
+ # ------------------------------------------------------------
-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;
-}
+ use JSON;
+ use IPC::Open2 qw/open2/;
-my $barred = $ses->request( 'open-ils.storage.actor.user.barred_barcodes' );
-while (my $resp = $barred->recv ) {
- print $resp->content . " B\n";
-}
-$barred->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 $penalized = $ses->request( 'open-ils.storage.actor.user.penalized_barcodes' );
-while (my $resp = $penalized->recv ) {
- print $resp->content . " D\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
+ # ------------------------------------------------------------
+
+ 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;
+
}
-$penalized->finish;
-$ses->disconnect;
-$ses->finish;
-
More information about the open-ils-commits
mailing list