[pve-devel] r5734 - in pve-access-control/trunk: . PVE

svn-commits at proxmox.com svn-commits at proxmox.com
Mon Mar 21 09:46:21 CET 2011


Author: dietmar
Date: 2011-03-21 09:46:21 +0100 (Mon, 21 Mar 2011)
New Revision: 5734

Modified:
   pve-access-control/trunk/ChangeLog
   pve-access-control/trunk/PVE/RPCEnvironment.pm
Log:
immediately move finished
	task to the index file.


Modified: pve-access-control/trunk/ChangeLog
===================================================================
--- pve-access-control/trunk/ChangeLog	2011-03-21 08:43:29 UTC (rev 5733)
+++ pve-access-control/trunk/ChangeLog	2011-03-21 08:46:21 UTC (rev 5734)
@@ -1,3 +1,8 @@
+2011-03-21  Proxmox Support Team  <support at proxmox.com>
+
+	* PVE/RPCEnvironment.pm (active_workers): immediately move finished
+	task to the index file.
+
 2011-03-17  Proxmox Support Team  <support at proxmox.com>
 
 	* PVE/RPCEnvironment.pm (active_workers): update/get worker list

Modified: pve-access-control/trunk/PVE/RPCEnvironment.pm
===================================================================
--- pve-access-control/trunk/PVE/RPCEnvironment.pm	2011-03-21 08:43:29 UTC (rev 5733)
+++ pve-access-control/trunk/PVE/RPCEnvironment.pm	2011-03-21 08:46:21 UTC (rev 5734)
@@ -302,6 +302,8 @@
 }
 
 # read/update list of active workers 
+# we move all finished tasks to the archive index,
+# but keep aktive and most recent task in the active file.
 sub active_workers  {
     my ($new_upid) = @_;
 
@@ -322,7 +324,6 @@
 
 	    my $pstart = PVE::ProcFSTools::read_proc_starttime($task->{pid});
 	    if ($pstart && ($pstart == $task->{pstart})) {
-		print "RUNNING $task->{upid}\n";
 		push @$tlist, $task;
 	    } else {
 		delete $task->{pid};
@@ -357,21 +358,14 @@
 	    $save = 1;
 	}
 
-	# we try to reduce the amount of data
-	# only list running tasks and task not older than 5 minutes
-	# try to limit to 25 tasks
-	my $ctime = time();
-	my $max = 25 - scalar(@$tlist);
-
 	my $archive = '';
+	my @arlist = ();
 	foreach my $task (@ta) {
-	    if (($max <= 0) || (($ctime - $task->{starttime}) > 60*5)) {
-		$archive .= sprintf("$task->{upid} %08X $task->{status}\n", 
-				    $task->{endtime});
+	    if (!$task->{saved}) {
+		$archive .= sprintf("$task->{upid} %08X $task->{status}\n", $task->{endtime});
 		$save = 1;
-	    } else {
-		push @$tlist, $task;
-		$max--;
+		push @arlist, $task;
+		$task->{saved} = 1;
 	    }
 	}
 
@@ -387,9 +381,23 @@
 	    my $err = $@;
 	    if ($err) {
 		syslog('err', $err);
-		$save = 0; # don't write changes
+		foreach my $task (@arlist) { # mark as not saved
+		    $task->{saved} = 0;
+		}
 	    }
 	}
+
+	# we try to reduce the amount of data
+	# list all running tasks and task and a few others
+	# try to limit to 25 tasks
+	my $ctime = time();
+	my $max = 25 - scalar(@$tlist);
+        foreach my $task (@ta) {
+	    last if $max <= 0;
+	    push @$tlist, $task;
+	    $max--;
+	}
+
 	PVE::INotify::write_file('active', $tlist) if $save;
 
 	return $tlist;
@@ -408,9 +416,10 @@
 # STDOUT,STDERR are redirected to the filename returned by upid_decode
 # NOTE: we simulate running in foreground if ($self->{type} eq 'cli')
 sub fork_worker {
-    my ($self, $dtype, $user, $function) = @_;
+    my ($self, $dtype, $id, $user, $function) = @_;
 
     $dtype = 'unknown' if !defined ($dtype);
+    $id = '' if !defined ($id);
 
     $user = 'root at pve' if !defined ($user);
 
@@ -438,7 +447,7 @@
 
     my $upid = PVE::Tools::upid_encode ({
 	node => $node, pid => $workerpuid, pstart => $pstart, 
-	starttime => $starttime, type => $dtype, user => $user });
+	starttime => $starttime, type => $dtype, id => $id, user => $user });
 
     my $outfh;
 




More information about the pve-devel mailing list