Tpac: longer timeout for marc "expert" search
authorBill Erickson <berick@esilibrary.com>
Fri, 16 Sep 2011 15:49:08 +0000 (11:49 -0400)
committerDan Scott <dscott@laurentian.ca>
Thu, 22 Sep 2011 04:16:57 +0000 (00:16 -0400)
Since MARC searches can take a while, raise the default timeout from
1 minute to 2, with the option (at the API layer) of raising it to 5.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Dan Scott <dscott@laurentian.ca>

Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm

index 2bc7062..ac8046b 100644 (file)
@@ -2161,7 +2161,7 @@ Presently, search uses the cache unconditionally.
 # FIXME: that example above isn't actually tested.
 # TODO: docache option?
 sub marc_search {
-       my( $self, $conn, $args, $limit, $offset ) = @_;
+       my( $self, $conn, $args, $limit, $offset, $timeout ) = @_;
 
        my $method = 'open-ils.storage.biblio.full_rec.multi_search';
        $method .= ".staff" if $self->api_name =~ /staff/;
@@ -2170,6 +2170,11 @@ sub marc_search {
     $limit  ||= 10;     # FIXME: what about $args->{limit} ?
     $offset ||=  0;     # FIXME: what about $args->{offset} ?
 
+    # allow caller to pass in a call timeout since MARC searches
+    # can take longer than the default 60-second timeout.  
+    # Default to 2 mins.  Arbitrarily cap at 5 mins.
+    $timeout = 120 if !$timeout or $timeout > 300;
+
        my @search;
        push( @search, ($_ => $$args{$_}) ) for (sort keys %$args);
        my $ckey = $pfx . md5_hex($method . OpenSRF::Utils::JSON->perl2JSON(\@search));
@@ -2177,13 +2182,19 @@ sub marc_search {
        my $recs = search_cache($ckey, $offset, $limit);
 
        if(!$recs) {
-               $recs = $U->storagereq($method, %$args) || [];
-               if( $recs ) {
+
+        my $ses = OpenSRF::AppSession->create('open-ils.storage');
+        my $req = $ses->request($method, %$args);
+        my $resp = $req->recv($timeout);
+
+        if($resp and $recs = $resp->content) {
                        put_cache($ckey, scalar(@$recs), $recs);
                        $recs = [ @$recs[$offset..($offset + ($limit - 1))] ];
                } else {
                        $recs = [];
                }
+
+        $ses->kill_me;
        }
 
        my $count = 0;
index bed087f..7dc650b 100644 (file)
@@ -338,10 +338,16 @@ sub marc_expert_search {
     # nothing to do
     return Apache2::Const::OK if @$query == 0;
 
-    my $results = $U->simplereq(
-        'open-ils.search', 
+    my $timeout = 120;
+    my $ses = OpenSRF::AppSession->create('open-ils.search');
+    my $req = $ses->request(
         'open-ils.search.biblio.marc',
-        {searches => $query, org_unit => $org_unit}, $limit, $offset);
+        {searches => $query, org_unit => $org_unit}, 
+        $limit, $offset, $timeout);
+
+    my $resp = $req->recv($timeout);
+    my $results = $resp ? $resp->content : undef;
+    $ses->kill_me;
 
     if (defined $U->event_code($results)) {
         $self->apache->log->warn(