コード例 #1
0
ファイル: Process.php プロジェクト: Victopia/prefw
}
// Start transaction before lock tables.
Database::beginTransaction();
// Pick next awaiting process
Database::locKTables([FRAMEWORK_COLLECTION_PROCESS . ' READ']);
$res = (int) Database::fetchField('SELECT IFNULL(SUM(`capacity`), 0) as occupation
    FROM `' . FRAMEWORK_COLLECTION_PROCESS . '`
    WHERE `pid` IS NOT NULL AND `pid` > 0');
Database::unlockTables(true);
if ($res >= $capLimit) {
    Log::debug('Active processes has occupied maximum server capacity, daemon exits.');
    Database::rollback();
    die;
}
unset($res, $capLimit);
Database::lockTables(array(FRAMEWORK_COLLECTION_PROCESS . ' LOW_PRIORITY WRITE', FRAMEWORK_COLLECTION_PROCESS . ' as `active` LOW_PRIORITY WRITE', FRAMEWORK_COLLECTION_PROCESS . ' as `inactive` LOW_PRIORITY WRITE'));
$process = Database::fetchRow('SELECT `inactive`.* FROM `' . FRAMEWORK_COLLECTION_PROCESS . '` as `inactive`
    LEFT JOIN ( SELECT `type`, SUM(`capacity`) as `occupation` FROM `' . FRAMEWORK_COLLECTION_PROCESS . '`
        WHERE `pid` IS NOT NULL GROUP BY `type` ) as `active`
      ON `active`.`type` = `inactive`.`type`
    WHERE `timestamp` <= CURRENT_TIMESTAMP
      AND `start_time` <= CURRENT_TIMESTAMP
      AND `inactive`.`pid` IS NULL
    ORDER BY `occupation`, `weight` DESC, `id`
    LIMIT 1;');
// No waiting jobs in queue.
if (!$process) {
    Database::unlockTables(true);
    Database::rollback();
    Log::debug('No more jobs to do, suicide.');
    die;
コード例 #2
0
ファイル: Process.php プロジェクト: Victopia/prefw
 /**
  * Updates process related info of specified property $name.
  *
  * Note: Updates to real table properties are ignored, as they are requried
  * by the process framework.
  */
 public static function set($name, $value)
 {
     Database::lockTables(FRAMEWORK_COLLECTION_PROCESS, FRAMEWORK_COLLECTION_LOG);
     $res = self::get();
     if (!$res) {
         Database::unlockTables();
         return false;
     }
     $readOnlyFields = ['id', 'command', 'type', 'weight', 'pid', 'timestamp'];
     if (in_array($name, $readOnlyFields)) {
         Database::unlockTables();
         return false;
     }
     if (is_null($value)) {
         unset($res[$name]);
     } else {
         $res[$name] = $value;
     }
     unset($res['timestamp']);
     $ret = Node::set($res);
     Database::unlockTables();
     // Clear data cache
     self::$_processData = null;
     return $ret;
 }