[LON-CAPA-cvs] cvs: loncom(version_2_6_X) /interface loncommon.pm

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Sun, 23 Mar 2008 23:06:34 -0000


raeburn		Sun Mar 23 19:06:34 2008 EDT

  Modified files:              (Branch: version_2_6_X)
    /loncom/interface	loncommon.pm 
  Log:
  - backport 1.643
  
  
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.636.2.3 loncom/interface/loncommon.pm:1.636.2.4
--- loncom/interface/loncommon.pm:1.636.2.3	Tue Mar 18 19:00:51 2008
+++ loncom/interface/loncommon.pm	Sun Mar 23 19:06:31 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.636.2.3 2008/03/18 23:00:51 raeburn Exp $
+# $Id: loncommon.pm,v 1.636.2.4 2008/03/23 23:06:31 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -78,6 +78,72 @@
 ## Global Variables
 ##
 
+# ----------------------------------------------- SSI with retries:
+#
+
+=pod
+
+=head1 Server Side include with retries:
+
+=over 4
+
+=item * &ssi_with_retries(resource,retries form)
+
+Performs an ssi with some number of retries.  Retries continue either
+until the result is ok or until the retry count supplied by the
+caller is exhausted.
+
+Inputs:
+
+=over 4
+
+resource   - Identifies the resource to insert.
+
+retries    - Count of the number of retries allowed.
+
+form       - Hash that identifies the rendering options.
+
+=back
+
+Returns:
+
+=over 4
+
+content    - The content of the response.  If retries were exhausted this is empty.
+
+response   - The response from the last attempt (which may or may not have been successful.
+
+=back
+
+=back
+
+=cut
+
+sub ssi_with_retries {
+    my ($resource, $retries, %form) = @_;
+
+
+    my $ok = 0;                 # True if we got a good response.
+    my $content;
+    my $response;
+
+    # Try to get the ssi done. within the retries count:
+
+    do {
+        ($content, $response) = &Apache::lonnet::ssi($resource, %form);
+        $ok      = $response->is_success;
+        $retries--;
+    } while (!$ok && ($retries > 0));
+
+    if (!$ok) {
+        $content = '';          # On error return an empty content.
+    }
+    return ($content, $response);
+
+}
+
+
+
 # ----------------------------------------------- Filetypes/Languages/Copyright
 my %language;
 my %supported_language;