This commit is contained in:
jygaulier
2012-01-19 21:01:03 +01:00
parent e5828f06bb
commit 5a5f86a97b
7 changed files with 1079 additions and 653 deletions

View File

@@ -90,34 +90,26 @@ class task_manager
continue;
try
{
if( ($lock = fopen( $lockdir . 'task.'.$row['task_id'].'.lock', 'a+')) )
{
if (flock($lock, LOCK_SH | LOCK_NB) === FALSE)
{
// already locked : running !
$row['pid'] = fgets($lock, 512);
}
else
{
// can lock : not running
flock($lock, LOCK_UN);
}
fclose($lock);
}
// if( ($lock = fopen( $lockdir . 'task.'.$row['task_id'].'.lock', 'a+')) )
// {
// if (flock($lock, LOCK_SH | LOCK_NB) === FALSE)
// {
// // already locked : running !
// $row['pid'] = fgets($lock, 512);
// }
// else
// {
// // can lock : not running
// flock($lock, LOCK_UN);
// }
// fclose($lock);
// }
$tasks[$row['task_id']] = new $classname($row['task_id']);
}
catch (Exception $e)
{
}
}
$this->tasks = $tasks;
@@ -175,8 +167,13 @@ class task_manager
public function get_scheduler_state2()
{
$ret = array('pid'=>NULL, 'qdelay'=>NULL);
$sql = "SELECT UNIX_TIMESTAMP()-UNIX_TIMESTAMP(schedqtime) AS qdelay, schedstatus AS status FROM sitepreff";
$stmt = $this->appbox->get_connection()->prepare($sql);
$stmt->execute();
$ret = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$ret['pid'] = NULL;
$appbox = appbox::get_instance();
$lockdir = $appbox->get_registry()->get('GV_RootPath') . 'tmp/locks/';
if( ($schedlock = fopen( $lockdir . 'scheduler.lock', 'a+')) )
@@ -184,12 +181,6 @@ class task_manager
if (flock($schedlock, LOCK_SH | LOCK_NB) === FALSE)
{
// already locked : running !
$sql = "SELECT UNIX_TIMESTAMP()-UNIX_TIMESTAMP(schedqtime) AS qdelay FROM sitepreff";
$stmt = $this->appbox->get_connection()->prepare($sql);
$stmt->execute();
$ret = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$ret['pid'] = fgets($schedlock, 512);
}
else