[LON-CAPA-cvs] cvs: loncom /publisher lonpublisher.pm

www lon-capa-cvs@mail.lon-capa.org
Wed, 05 Jan 2005 20:11:19 -0000


www		Wed Jan  5 15:11:19 2005 EDT

  Modified files:              
    /loncom/publisher	lonpublisher.pm 
  Log:
  Bug #1104: publication takes too long
  
  Put notifications into cleanup phase - seems too good to be true.
  
  
Index: loncom/publisher/lonpublisher.pm
diff -u loncom/publisher/lonpublisher.pm:1.180 loncom/publisher/lonpublisher.pm:1.181
--- loncom/publisher/lonpublisher.pm:1.180	Mon Oct 11 13:40:46 2004
+++ loncom/publisher/lonpublisher.pm	Wed Jan  5 15:11:19 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Publication Handler
 #
-# $Id: lonpublisher.pm,v 1.180 2004/10/11 17:40:46 albertel Exp $
+# $Id: lonpublisher.pm,v 1.181 2005/01/05 20:11:19 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1541,42 +1541,12 @@
             "<font color=\"red\">".&mt('Failed to write metadata copy').", $!, ".&mt('FAIL')."</font>";
     }
     $r->rflush;
-# --------------------------------------------------- Send update notifications
 
-    my @subscribed=&get_subscribed_hosts($target);
-    foreach my $subhost (@subscribed) {
-	$r->print('<p>'.&mt('Notifying host').' '.$subhost.':');$r->rflush;
-	print $logfile "\nNotifying host ".$subhost.':';
-	my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
-	$r->print($reply.'</p><br />');$r->rflush;
-	print $logfile $reply;
-    }
-    
-# ---------------------------------------- Send update notifications, meta only
+# ------------------------------------------------------------- Trigger updates
+    $ENV{'internal.publication.target'}=$target;
+    $ENV{'internal.publication.source'}=$source;
+    $r->register_cleanup(\&notify);
 
-    my @subscribedmeta=&get_subscribed_hosts("$target.meta");
-    foreach my $subhost (@subscribedmeta) {
-	$r->print('<p>'.
-&mt('Notifying host for metadata only').' '.$subhost.':');$r->rflush;
-	print $logfile "\nNotifying host for metadata only ".$subhost.':';
-	my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
-					    $subhost);
-	$r->print($reply.'</p><br />');$r->rflush;
-	print $logfile $reply;
-    }
-    
-# --------------------------------------------------- Notify subscribed courses
-    my %courses=&coursedependencies($target);
-    my $now=time;
-    foreach (keys %courses) {
-	$r->print('<p>'.&mt('Notifying course').' '.$_.':');$r->rflush;
-	print $logfile "\nNotifying host ".$_.':';
-        my ($cdom,$cname)=split(/\_/,$_);
-	my $reply=&Apache::lonnet::cput
-                  ('versionupdate',{$target => $now},$cdom,$cname);
-	$r->print($reply.'</p><br />');$r->rflush;
-	print $logfile $reply;
-    }
 # ------------------------------------------------ Provide link to new resource
     unless ($batch) {
         my $thisdistarget=$target;
@@ -1598,9 +1568,45 @@
                    '"><font size="+2">'.
 		  &mt('Back to Source Directory').'</font></a></p>');
     }
+    $logfile->close();
     return '<p><font color="green">'.&mt('Done').'</font></p>';
 }
 
+# =============================================================== Notifications
+sub notify {  
+# --------------------------------------------------- Send update notifications
+    my $target=$ENV{'internal.publication.target'};
+    my $source=$ENV{'internal.publication.source'};
+    my $logfile=Apache::File->new('>>'.$source.'.log');
+    print $logfile "\nCleanup phase: Notifications\n";
+    my @subscribed=&get_subscribed_hosts($target);
+    foreach my $subhost (@subscribed) {
+	print $logfile "\nNotifying host ".$subhost.':';
+	my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
+	print $logfile $reply;
+    }
+# ---------------------------------------- Send update notifications, meta only
+    my @subscribedmeta=&get_subscribed_hosts("$target.meta");
+    foreach my $subhost (@subscribedmeta) {
+	print $logfile "\nNotifying host for metadata only ".$subhost.':';
+	my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
+					    $subhost);
+	print $logfile $reply;
+    } 
+# --------------------------------------------------- Notify subscribed courses
+    my %courses=&coursedependencies($target);
+    my $now=time;
+    foreach (keys %courses) {
+	print $logfile "\nNotifying course ".$_.':';
+        my ($cdom,$cname)=split(/\_/,$_);
+	my $reply=&Apache::lonnet::cput
+                  ('versionupdate',{$target => $now},$cdom,$cname);
+	print $logfile $reply;
+    }
+    print $logfile "\n============ Done ============\n";
+    $logfile->close();
+}
+
 #########################################
 
 sub batchpublish {