[vhffs-dev] [1259] fixed a little race condition

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 1259
Author:   gradator
Date:     2008-09-25 19:50:18 +0200 (Thu, 25 Sep 2008)

Log Message:
-----------
fixed a little race condition

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Robots/Cron.pm
    trunk/vhffs-robots/src/cron_scheduler.pl


Modified: trunk/vhffs-api/src/Vhffs/Robots/Cron.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Cron.pm	2008-09-25 17:28:52 UTC (rev 1258)
+++ trunk/vhffs-api/src/Vhffs/Robots/Cron.pm	2008-09-25 17:50:18 UTC (rev 1259)
@@ -62,7 +62,7 @@
 	my $main = shift;
 	my $maxexectime = shift;
 
-	my $sql = 'SELECT c.cron_id, c.cronpath, c.interval, c.reportmail, c.lastrundate, c.lastrunreturncode, c.nextrundate, c.running, o.owner_uid, o.owner_gid, o.object_id, o.date_creation, o.description, o.state FROM vhffs_cron c INNER JOIN vhffs_object o ON c.object_id=o.object_id WHERE o.state=? AND c.running!=0 AND c.nextrundate IS NOT NULL AND c.nextrundate<?';
+	my $sql = 'SELECT c.cron_id, c.cronpath, c.interval, c.reportmail, c.lastrundate, c.lastrunreturncode, c.nextrundate, c.running, o.owner_uid, o.owner_gid, o.object_id, o.date_creation, o.description, o.state FROM vhffs_cron c INNER JOIN vhffs_object o ON c.object_id=o.object_id WHERE o.state=? AND c.running!=0 AND ( c.nextrundate IS NULL OR c.nextrundate<? )';
 	my $dbh = $main->get_db_object();
 	my $sth = $dbh->prepare($sql);
 	$sth->execute( Vhffs::Constants::ACTIVATED , time() - $maxexectime ) or return undef;

Modified: trunk/vhffs-robots/src/cron_scheduler.pl
===================================================================
--- trunk/vhffs-robots/src/cron_scheduler.pl	2008-09-25 17:28:52 UTC (rev 1258)
+++ trunk/vhffs-robots/src/cron_scheduler.pl	2008-09-25 17:50:18 UTC (rev 1259)
@@ -89,6 +89,7 @@
 		$crons = Vhffs::Robots::Cron::get_stalled_jobs( $vhffs , $maxexectime + 60 );
 		foreach my $c ( @{$crons} )  {
 			$c->quick_reset();
+			print scalar localtime().'    * '.$c->get_cron_id.' '.$c->get_cronpath."\n";
 		}
 
 		$prevrun = time();
@@ -202,8 +203,8 @@
 	${%jobs}{$cron_id}{'runat'} = ${%jobs}{$cron_id}{'createdat'} + int(rand 4) +2;
 	${%jobs}{$cron_id}{'startedat'} = undef;
 	${%jobs}{$cron_id}{'status'} = STATUS_CREATED;
+	$cron->quick_set_nextrundate( ${%jobs}{$cron_id}{'runat'} );  # so that we know when the process will/has be/been started in nextrundate
 	$cron->quick_inc_running();
-	$cron->quick_set_nextrundate( ${%jobs}{$cron_id}{'runat'} );  # so that we know when the process will/has be/been started in nextrundate
 
 	print scalar localtime().'    + '.$cron_id.' '.$cron->get_cronpath."\n";
 	return ${%jobs}{$cron_id};
@@ -230,7 +231,7 @@
 		destroy_job( $job );
 		return 1;
 	}
-	print scalar localtime().'    = '.$cron_id.' '.$cron->get_cronpath."\n";
+	print scalar localtime().'    > '.$cron_id.' '.$cron->get_cronpath."\n";
 
 	my $par = new IO::Handle->new();
 	my $son = new IO::Handle->new();


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/