예제 #1
0
$solutionId = $argv[1];
if (empty($solutionId)) {
    Logger::error('judge', '缺少参数:$solutionId');
    exit(1);
}
// 从评判队列中获取该条信息
$queueInfo = OjJudgeInterface::getRow(array('where' => array(array('solution_id', '=', $solutionId))));
if (empty($queueInfo)) {
    Logger::error('judge', "评判队列中不存在Solution!solutionId={$solutionId}");
    exit(1);
}
$trans = new Trans(DbConfig::$SERVER_TRANS);
$trans->begin();
// 保存result
try {
    OjSolutionInterface::save(array('id' => $solutionId, 'time_cost' => $queueInfo['time_cost'], 'memory_cost' => $queueInfo['memory_cost'], 'judge_time' => $queueInfo['judge_time'], 'run_id' => $queueInfo['id'], 'result' => $queueInfo['result'], 'trans' => $trans));
} catch (Exception $e) {
    Logger::error('judge', "solutionId={$solutionId},保存solution失败," . $e->getMessage());
    $trans->rollback();
    throw $e;
}
// 保存log
try {
    OjSolutionLogInterface::save(array('trans' => $trans, 'solution_id' => $solutionId, 'ce' => $queueInfo['ce'], 're' => $queueInfo['re'], 'detail' => $queueInfo['detail']));
} catch (Exception $e) {
    Logger::error('judge', "solutionId={$solutionId},保存log失败," . $e->getMessage());
    $trans->rollback();
    throw $e;
}
$trans->commit();
exit(0);
예제 #2
0
 /**
  * 同步数据到oj_solution
  *
  * @throws  Exception
  */
 public function sync()
 {
     $solutionInfo = OjSolutionInterface::getById(array('id' => $this->solutionId));
     if (empty($solutionInfo)) {
         Logger::error('judge', "SOLUTION_ID:{$this->solutionId},Solution不存在!");
         throw new Exception("SOLUTION_ID:{$this->solutionId},Solution不存在!");
     }
     if ($solutionInfo['remote'] != StatusVars::REMOTE_POJ) {
         Logger::error('judge', "SOLUTION_ID:{$this->solutionId},必须是POJ的Solution!");
         throw new Exception("SOLUTION_ID:{$this->solutionId},必须是POJ的Solution!");
     }
     if (empty($solutionInfo['run_id'])) {
         Logger::error('judge', "RUN_ID为0!");
         throw new Exception("SOLUTION_ID:{$this->solutionId},RUN_ID为0!");
     }
     if ($solutionInfo['remote_uid'] != -1 && $solutionInfo['remote_uid'] != $this->uid) {
         Logger::error('judge', "SOLUTION_ID:{$this->solutionId},当前uid不等于remote_uid,无法获取其他用户的状态!");
         throw new Exception("SOLUTION_ID:{$this->solutionId},当前uid不等于remote_uid,无法获取其他用户的状态!");
     }
     // 尝试多次获取结果
     $rowInfo = array();
     $i = 1;
     while ($i <= 10) {
         $rowInfo = $this->getResult($solutionInfo['run_id']);
         if (false === $rowInfo || in_array($rowInfo['result'], StatusVars::$pojResultMap)) {
             break;
         }
         $i > 5 ? sleep(2) : usleep(500000);
         $i++;
     }
     // 获取获取结果超时
     if (false === $rowInfo) {
         Logger::info('judge', "SOLUTION_ID:{$this->solutionId},获取结果失败2,写入TIME_OUT");
         $data = array('id' => $this->solutionId, 'result' => StatusVars::TIME_OUT, 'time_cost' => 0, 'memory_cost' => 0);
         OjSolutionInterface::save($data);
     } else {
         Logger::info('judge', "SOLUTION_ID:{$this->solutionId},POJ远程judge成功!尝试次数:{$i}");
         $trans = new Trans(DbConfig::$SERVER_TRANS);
         $trans->begin();
         $data = array('trans' => $trans, 'id' => $this->solutionId, 'result' => $rowInfo['result'], 'time_cost' => $rowInfo['time_cost'], 'memory_cost' => $rowInfo['memory_cost']);
         OjSolutionInterface::save($data);
         // 保存Log
         $dataLog = array('trans' => $trans, 'solution_id' => $this->solutionId, 'ce' => Arr::get('ce', $rowInfo['judge_log'], ''), 're' => Arr::get('re', $rowInfo['judge_log'], ''));
         OjSolutionLogInterface::save($dataLog);
         $trans->commit();
     }
 }
예제 #3
0
 public static function getDetail($id)
 {
     $solutionInfo = self::getById($id);
     if (empty($solutionInfo)) {
         return array();
     }
     $sourceInfo = OjSolutionCodeInterface::getByField(array('solution_id' => $id));
     $solutionInfo['has_log'] = OjSolutionHelper::hasLog($solutionInfo);
     $logInfo = array();
     if ($solutionInfo['has_log']) {
         $logInfo = OjSolutionLogInterface::getByField(array('solution_id' => $id));
     }
     $solutionInfo['source'] = Arr::get('source', $sourceInfo, '', true);
     $solutionInfo['source_format'] = htmlspecialchars($solutionInfo['source'], ENT_COMPAT, 'UTF-8');
     $solutionInfo['ce'] = Arr::get('ce', $logInfo, '', true);
     $solutionInfo['re'] = Arr::get('re', $logInfo, '', true);
     $solutionInfo['detail'] = Arr::get('detail', $logInfo, '', true);
     return $solutionInfo;
 }