[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm lonprintout.pm
foxr
lon-capa-cvs-allow@mail.lon-capa.org
Mon, 03 Mar 2008 10:50:27 -0000
foxr Mon Mar 3 05:50:27 2008 EDT
Modified files:
/loncom/interface loncommon.pm lonprintout.pm
Log:
Factor the logic of ssi_with_retries out into loncommon leaving only the
error handling to be implemented according to the policies of the calling
module (lonprintout in this case, but later grades too).
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.642 loncom/interface/loncommon.pm:1.643
--- loncom/interface/loncommon.pm:1.642 Fri Feb 29 14:07:07 2008
+++ loncom/interface/loncommon.pm Mon Mar 3 05:50:26 2008
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.642 2008/02/29 19:07:07 raeburn Exp $
+# $Id: loncommon.pm,v 1.643 2008/03/03 10:50:26 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -78,6 +78,58 @@
## Global Variables
##
+
+# ----------------------------------------------- SSI with retries:
+#
+
+=pod
+
+=head1 Server Side incliude 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:
+resource - Identifies the resource to insert.
+retries - Count of the number of retries allowed.
+form - Hash that identifies the rendering options.
+
+Returns:
+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.
+
+=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;
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.515 loncom/interface/lonprintout.pm:1.516
--- loncom/interface/lonprintout.pm:1.515 Tue Feb 26 05:46:14 2008
+++ loncom/interface/lonprintout.pm Mon Mar 3 05:50:26 2008
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Printout
#
-# $Id: lonprintout.pm,v 1.515 2008/02/26 10:46:14 foxr Exp $
+# $Id: lonprintout.pm,v 1.516 2008/03/03 10:50:26 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -144,30 +144,15 @@
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));
-
- # Two cases: ok is true we have valid data, if not, retries have been exhausted
- # if ok is true, $response->content is what we want to return.. otherwise
- # set the error information:
-
- if ($ok) {
- return $content;
- } else {
+ my ($content, $response) = &Apache::loncommon::ssi_with_retries($resource, $retries, %form);
+ if (!$response->is_success) {
$ssi_error = 1;
$ssi_last_error_resource = $resource;
- $ssi_last_error = $response->code." ". $response->message;
- return ''; # Nothing we can add to the printout that makes sense.
+ $ssi_last_error = $response->code . " " . $response->message;
}
+
+ return $content;
+
}
#