backporting request timeout support
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 18 Dec 2008 22:46:38 +0000 (22:46 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 18 Dec 2008 22:46:38 +0000 (22:46 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_2_4@11624 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Utils/CStoreEditor.pm

index cb53d1e..e44437c 100644 (file)
@@ -145,6 +145,12 @@ sub authtoken {
        return $self->{authtoken};
 }
 
+sub timeout {
+    my($self, $to) = @_;
+    $self->{timeout} = $to if defined $to;
+    return defined($self->{timeout}) ? $self->{timeout} : 60;
+}
+
 # -----------------------------------------------------------------------------
 # fetches the session, creating if necessary.  If 'xact' is true on this
 # object, a db session is created
@@ -258,7 +264,7 @@ sub finish {
 sub request {
        my( $self, $method, @params ) = @_;
 
-       my $val;
+    my $val;
        my $err;
        my $argstr = __arg_to_string( (scalar(@params)) == 1 ? $params[0] : \@params);
 
@@ -270,21 +276,24 @@ sub request {
                #throw OpenSRF::EX::ERROR ("CStoreEditor lost it's connection - transaction cannot continue");
        }
 
+
        try {
 
-      my $req = $self->session->request($method, @params);
+        my $req = $self->session->request($method, @params);
+
+        if($self->substream) {
+            $self->log(D,"running in substream mode");
+            $val = [];
+            while( my $resp = $req->recv(timeout => $self->timeout) ) {
+                push(@$val, $resp->content) if $resp->content;
+            }
 
-      if( $self->substream ) {
-         $self->log(D,"running in substream mode");
-         $val = [];
-         while( my $resp = $req->recv ) {
-            push(@$val, $resp->content) if $resp->content;
-         }
-      } else {
-         $val = $req->gather(1);
-      }
+        } else {
+            my $resp = $req->recv(timeout => $self->timeout);
+            $val = $resp->content;
+        }
 
-               #$val = $self->session->request($method, @params)->gather(1);
+        $req->finish;
 
        } catch Error with {
                $err = shift;
@@ -494,6 +503,7 @@ sub runmethod {
        $method =~ s/search/id_list/o if $options->{idlist};
 
     $method =~ s/\.atomic$//o if $self->substream($$options{substream} || 0);
+    $self->timeout($$options{timeout});
 
        # remove any stale events
        $self->clear_event;