use of top.hcode.hoj.pojo.entity.judge.Judge in project HOJ by HimitZH.
the class UserRecordEntityServiceImpl method tryAgainUpdate.
@Transactional(isolation = Isolation.READ_COMMITTED)
public boolean tryAgainUpdate(String uid, Integer score) {
boolean retryable;
int attemptNumber = 0;
do {
// 查询最新版本号
QueryWrapper<Judge> judgeQueryWrapper = new QueryWrapper<>();
// 非比赛提交
judgeQueryWrapper.isNotNull("score").orderByDesc("score").isNull("cid").last("limit 1");
Judge lastHighScoreJudge = judgeEntityService.getOne(judgeQueryWrapper);
// 更新
boolean success = true;
if (lastHighScoreJudge == null) {
UpdateWrapper<UserRecord> userRecordUpdateWrapper = new UpdateWrapper<>();
userRecordUpdateWrapper.set("total_score", score).eq("uid", uid);
success = userRecordMapper.update(null, userRecordUpdateWrapper) == 1;
} else if (lastHighScoreJudge.getScore() < score) {
// 如果之前该题目最高得分的提交比现在得分低,也需要修改
int addValue = score - lastHighScoreJudge.getScore();
UpdateWrapper<UserRecord> userRecordUpdateWrapper = new UpdateWrapper<>();
userRecordUpdateWrapper.setSql("total_score=total_score+" + addValue).eq("uid", uid);
success = userRecordMapper.update(null, userRecordUpdateWrapper) == 1;
}
if (success) {
return true;
} else {
attemptNumber++;
retryable = attemptNumber < 8;
if (attemptNumber == 8) {
log.error("更新user_record表超过最大重试次数");
break;
}
try {
Thread.sleep(300);
} catch (InterruptedException e) {
log.error(e.getMessage());
}
}
} while (retryable);
return false;
}
use of top.hcode.hoj.pojo.entity.judge.Judge in project HOJ by HimitZH.
the class RemoteJudgeToSubmit method process.
public boolean process(RemoteJudgeStrategy remoteJudgeStrategy) {
RemoteJudgeDTO remoteJudgeDTO = remoteJudgeStrategy.getRemoteJudgeDTO();
log.info("Ready Send Task to RemoteJudgeDTO => {}", remoteJudgeDTO);
String errLog = null;
try {
remoteJudgeStrategy.submit();
} catch (Exception e) {
log.error("Submit Failed! Error:", e);
errLog = e.getMessage();
}
Long submitId = remoteJudgeDTO.getSubmitId();
// 提交失败 前端手动按按钮再次提交 修改状态 STATUS_SUBMITTED_FAILED
if (submitId == null || submitId == -1L) {
// 将使用的账号放回对应列表
log.error("[{}] Submit Failed! Begin to return the account to other task!", remoteJudgeDTO.getOj());
remoteJudgeService.changeAccountStatus(remoteJudgeDTO.getOj(), remoteJudgeDTO.getUsername());
if (RemoteJudgeContext.openCodeforcesFixServer) {
if (remoteJudgeDTO.getOj().equals(Constants.RemoteJudge.GYM_JUDGE.getName()) || remoteJudgeDTO.getOj().equals(Constants.RemoteJudge.CF_JUDGE.getName())) {
// 对CF特殊,归还判题机权限
log.error("[{}] Submit Failed! Begin to return the Server Status to other task!", remoteJudgeDTO.getOj());
remoteJudgeService.changeServerSubmitCFStatus(remoteJudgeDTO.getServerIp(), remoteJudgeDTO.getServerPort());
}
}
// 更新此次提交状态为提交失败!
UpdateWrapper<Judge> judgeUpdateWrapper = new UpdateWrapper<>();
judgeUpdateWrapper.set("status", Constants.Judge.STATUS_SUBMITTED_FAILED.getStatus()).set("error_message", errLog).eq("submit_id", remoteJudgeDTO.getJudgeId());
judgeEntityService.update(judgeUpdateWrapper);
// 更新其它表
judgeContext.updateOtherTable(remoteJudgeDTO.getSubmitId(), Constants.Judge.STATUS_SYSTEM_ERROR.getStatus(), remoteJudgeDTO.getCid(), remoteJudgeDTO.getUid(), remoteJudgeDTO.getPid(), remoteJudgeDTO.getGid(), null, null);
return false;
}
// 提交成功顺便更新状态为-->STATUS_PENDING 等待判题中...
judgeEntityService.updateById(new Judge().setSubmitId(remoteJudgeDTO.getJudgeId()).setStatus(Constants.Judge.STATUS_PENDING.getStatus()).setVjudgeSubmitId(submitId).setVjudgeUsername(remoteJudgeDTO.getUsername()).setVjudgePassword(remoteJudgeDTO.getPassword()).setJudger(name));
log.info("[{}] Submit Successfully! The submit_id of remote judge is [{}]. Waiting the result of the task!", submitId, remoteJudgeDTO.getOj());
return true;
}
use of top.hcode.hoj.pojo.entity.judge.Judge in project HOJ by HimitZH.
the class UserRecordServiceImpl method updateRecord.
/**
* @MethodNameupdateRecord
* @Params * @param null
* @Description 本方法不启用,不适合数据一致性
* @Return
* @Since 2021/6/2
*/
@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
@Async
@Override
@Deprecated
public void updateRecord(String uid, Long submitId, Long pid, Integer score) {
QueryWrapper<Judge> judgeQueryWrapper = new QueryWrapper<>();
judgeQueryWrapper.isNotNull("score").eq("cid", // 非比赛提交
0).eq("pid", pid).eq("uid", uid).ne("submit_id", submitId).orderByDesc("score").last("limit 1");
Judge lastHighScoreJudge = judgeService.getOne(judgeQueryWrapper);
// 之前没有提交过,那么就需要修改
boolean result = true;
if (lastHighScoreJudge == null) {
UpdateWrapper<UserRecord> userRecordUpdateWrapper = new UpdateWrapper<>();
userRecordUpdateWrapper.setSql("total_score=total_score+" + score).eq("uid", uid);
result = userRecordMapper.update(null, userRecordUpdateWrapper) == 1;
} else if (lastHighScoreJudge.getScore() < score) {
// 如果之前该题目最高得分的提交比现在得分低,也需要修改
int addValue = score - lastHighScoreJudge.getScore();
UpdateWrapper<UserRecord> userRecordUpdateWrapper = new UpdateWrapper<>();
userRecordUpdateWrapper.setSql("total_score=total_score+" + addValue).eq("uid", uid);
result = userRecordMapper.update(null, userRecordUpdateWrapper) == 1;
}
if (result) {
return;
} else {
// 失败则开始尝试
tryAgainUpdate(uid, score);
}
}
use of top.hcode.hoj.pojo.entity.judge.Judge in project HOJ by HimitZH.
the class TrainingRecordServiceImpl method saveBatchNewRecordByJudgeList.
private void saveBatchNewRecordByJudgeList(List<Judge> judgeList, Long tid, Long tpId, HashMap<Long, Long> pidMapTPid) {
if (!CollectionUtils.isEmpty(judgeList)) {
List<TrainingRecord> trainingRecordList = new ArrayList<>();
for (Judge judge : judgeList) {
TrainingRecord trainingRecord = new TrainingRecord().setPid(judge.getPid()).setSubmitId(judge.getSubmitId()).setTid(tid).setUid(judge.getUid());
if (pidMapTPid != null) {
trainingRecord.setTpid(pidMapTPid.get(judge.getPid()));
}
if (tpId != null) {
trainingRecord.setTpid(tpId);
}
trainingRecordList.add(trainingRecord);
}
saveBatch(trainingRecordList);
}
}
use of top.hcode.hoj.pojo.entity.judge.Judge in project HOJ by HimitZH.
the class JudgeDispatcher method sendTask.
public void sendTask(Judge judge, String token, Boolean isContest) {
JSONObject task = new JSONObject();
task.set("judge", judge);
task.set("token", token);
task.set("isContest", isContest);
try {
boolean isOk;
if (isContest) {
isOk = redisUtils.llPush(Constants.Queue.CONTEST_JUDGE_WAITING.getName(), JSONUtil.toJsonStr(task));
} else {
isOk = redisUtils.llPush(Constants.Queue.GENERAL_JUDGE_WAITING.getName(), JSONUtil.toJsonStr(task));
}
if (!isOk) {
judgeService.updateById(new Judge().setSubmitId(judge.getSubmitId()).setStatus(Constants.Judge.STATUS_SUBMITTED_FAILED.getStatus()).setErrorMessage("Please try to submit again!"));
}
// 调用判题任务处理
judgeReceiver.processWaitingTask();
} catch (Exception e) {
log.error("调用redis将判题纳入判题等待队列异常,此次判题任务判为系统错误--------------->{}", e.getMessage());
judgeService.failToUseRedisPublishJudge(judge.getSubmitId(), judge.getPid(), isContest);
}
}
Aggregations