[LON-CAPA-cvs] cvs: loncom /lonnet/perl lonnet.pm

raeburn raeburn at source.lon-capa.org
Tue Aug 16 18:10:13 EDT 2016


raeburn		Tue Aug 16 22:10:13 2016 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Add two new optional args to &get_query_reply() 
   - $sleep and $loopmax (defaults if not specified are: 0.2 and 100).
   - A larger value for $sleep is used when waiting for the response to a
     "fetchenrollment" query sent to lonsql by Autoenroll.pl.
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1316 loncom/lonnet/perl/lonnet.pm:1.1317
--- loncom/lonnet/perl/lonnet.pm:1.1316	Mon Aug  1 18:05:22 2016
+++ loncom/lonnet/perl/lonnet.pm	Tue Aug 16 22:10:12 2016
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1316 2016/08/01 18:05:22 raeburn Exp $
+# $Id: lonnet.pm,v 1.1317 2016/08/16 22:10:12 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -7875,10 +7875,12 @@
 
 sub fetch_enrollment_query {
     my ($context,$affiliatesref,$replyref,$dom,$cnum) = @_;
-    my $homeserver;
+    my ($homeserver,$sleep,$loopmax);
     my $maxtries = 1;
     if ($context eq 'automated') {
         $homeserver = $perlvar{'lonHostID'};
+        $sleep = 2;
+        $loopmax = 100;
         $maxtries = 10; # will wait for up to 2000s for retrieval of classlist data before timeout
     } else {
         $homeserver = &homeserver($cnum,$dom);
@@ -7896,10 +7898,10 @@
         &logthis('fetch_enrollment_query: invalid queryid: '.$queryid.' for host: '.$host.' and homeserver: '.$homeserver.' context: '.$context.' '.$cnum); 
         return 'error: '.$queryid;
     }
-    my $reply = &get_query_reply($queryid);
+    my $reply = &get_query_reply($queryid,$sleep,$loopmax);
     my $tries = 1;
     while (($reply=~/^timeout/) && ($tries < $maxtries)) {
-        $reply = &get_query_reply($queryid);
+        $reply = &get_query_reply($queryid,$sleep,$loopmax);
         $tries ++;
     }
     if ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
@@ -7941,11 +7943,17 @@
 }
 
 sub get_query_reply {
-    my $queryid=shift;
+    my ($queryid,$sleep,$loopmax) = @_;;
+    if (($sleep eq '') || ($sleep !~ /^\d+\.?\d*$/)) {
+        $sleep = 0.2;
+    }
+    if (($loopmax eq '') || ($loopmax =~ /\D/)) {
+        $loopmax = 100;
+    }
     my $replyfile=LONCAPA::tempdir().$queryid;
     my $reply='';
-    for (1..100) {
-	sleep(0.2);
+    for (1..$loopmax) {
+	sleep($sleep);
         if (-e $replyfile.'.end') {
 	    if (open(my $fh,$replyfile)) {
 		$reply = join('',<$fh>);




More information about the LON-CAPA-cvs mailing list