fix something cause judge bug
This commit is contained in:
parent
ddce7a2d40
commit
ac8967425d
|
@ -22,14 +22,17 @@ import top.hcode.hoj.crawler.problem.ProblemStrategy;
|
|||
import top.hcode.hoj.judge.Dispatcher;
|
||||
import top.hcode.hoj.pojo.dto.ProblemDto;
|
||||
import top.hcode.hoj.pojo.entity.judge.CompileDTO;
|
||||
import top.hcode.hoj.pojo.entity.judge.Judge;
|
||||
import top.hcode.hoj.pojo.entity.problem.Problem;
|
||||
import top.hcode.hoj.pojo.entity.problem.ProblemCase;
|
||||
import top.hcode.hoj.pojo.vo.UserRolesVo;
|
||||
import top.hcode.hoj.service.judge.impl.JudgeServiceImpl;
|
||||
import top.hcode.hoj.service.problem.impl.ProblemCaseServiceImpl;
|
||||
import top.hcode.hoj.service.problem.impl.ProblemServiceImpl;
|
||||
import top.hcode.hoj.utils.Constants;
|
||||
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.validation.Valid;
|
||||
|
@ -58,6 +61,9 @@ public class AdminProblemController {
|
|||
@Value("${hoj.judge.token}")
|
||||
private String judgeToken;
|
||||
|
||||
@Resource
|
||||
private JudgeServiceImpl judgeService;
|
||||
|
||||
|
||||
@GetMapping("/get-problem-list")
|
||||
@RequiresAuthentication
|
||||
|
@ -163,14 +169,16 @@ public class AdminProblemController {
|
|||
@Transactional(rollbackFor = Exception.class)
|
||||
public CommonResult updateProblem(@RequestBody ProblemDto problemDto, HttpServletRequest request) {
|
||||
|
||||
String problemId = problemDto.getProblem().getProblemId().toUpperCase();
|
||||
QueryWrapper<Problem> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("problem_id", problemDto.getProblem().getProblemId().toUpperCase());
|
||||
queryWrapper.eq("problem_id", problemId);
|
||||
Problem problem = problemService.getOne(queryWrapper);
|
||||
|
||||
// 如果problem_id不是原来的且已存在该problem_id,则修改失败!
|
||||
if (problem != null && problem.getId().longValue() != problemDto.getProblem().getId()) {
|
||||
return CommonResult.errorResponse("当前的Problem ID 已被使用,请重新更换新的!", CommonResult.STATUS_FAIL);
|
||||
}
|
||||
|
||||
// 获取当前登录的用户
|
||||
HttpSession session = request.getSession();
|
||||
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
|
||||
|
@ -179,6 +187,12 @@ public class AdminProblemController {
|
|||
|
||||
boolean result = problemService.adminUpdateProblem(problemDto);
|
||||
if (result) { // 更新成功
|
||||
if (problem == null) { // 说明改了problemId,同步一下judge表
|
||||
UpdateWrapper<Judge> judgeUpdateWrapper = new UpdateWrapper<>();
|
||||
judgeUpdateWrapper.eq("pid", problemDto.getProblem().getId())
|
||||
.set("display_pid", problemId);
|
||||
judgeService.update(judgeUpdateWrapper);
|
||||
}
|
||||
return CommonResult.successResponse(null, "修改成功!");
|
||||
} else {
|
||||
return CommonResult.errorResponse("修改失败", CommonResult.STATUS_FAIL);
|
||||
|
|
|
@ -166,10 +166,9 @@ public class JudgeController {
|
|||
|
||||
// 将提交加入任务队列
|
||||
if (judgeDto.getIsRemote()) { // 如果是远程oj判题
|
||||
remoteJudgeDispatcher.sendTask(judge, judgeToken, judge.getDisplayPid(), isContestSubmission,
|
||||
1, false);
|
||||
remoteJudgeDispatcher.sendTask(judge, judgeToken, judge.getDisplayPid(), isContestSubmission, false);
|
||||
} else {
|
||||
judgeDispatcher.sendTask(judge, judgeToken, isContestSubmission, 1);
|
||||
judgeDispatcher.sendTask(judge, judgeToken, isContestSubmission);
|
||||
}
|
||||
|
||||
return CommonResult.successResponse(judge, "代码提交成功!");
|
||||
|
@ -248,9 +247,9 @@ public class JudgeController {
|
|||
if (problem.getIsRemote()) { // 如果是远程oj判题
|
||||
|
||||
remoteJudgeDispatcher.sendTask(judge, judgeToken, problem.getProblemId(),
|
||||
judge.getCid() != 0, 1, isHasSubmitIdRemoteRejudge);
|
||||
judge.getCid() != 0, isHasSubmitIdRemoteRejudge);
|
||||
} else {
|
||||
judgeDispatcher.sendTask(judge, judgeToken, judge.getCid() != 0, 1);
|
||||
judgeDispatcher.sendTask(judge, judgeToken, judge.getCid() != 0);
|
||||
}
|
||||
return CommonResult.successResponse(judge, "重新提交成功!");
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ public class Dispatcher {
|
|||
|
||||
// 尝试600s
|
||||
AtomicInteger count = new AtomicInteger(0);
|
||||
String key = UUID.randomUUID().toString() + data.getJudge().getSubmitId();
|
||||
String key = UUID.randomUUID().toString() + submitId;
|
||||
final String finalOj = oj;
|
||||
Runnable getResultTask = new Runnable() {
|
||||
@Override
|
||||
|
|
|
@ -25,20 +25,18 @@ public class RemoteJudgeDispatcher {
|
|||
@Autowired
|
||||
private RemoteJudgeReceiver remoteJudgeReceiver;
|
||||
|
||||
public void sendTask(Judge judge, String token, String remoteJudgeProblem, Boolean isContest,
|
||||
Integer tryAgainNum, Boolean isHasSubmitIdRemoteReJudge) {
|
||||
public void sendTask(Judge judge, String token, String remoteJudgeProblem, Boolean isContest, Boolean isHasSubmitIdRemoteReJudge) {
|
||||
JSONObject task = new JSONObject();
|
||||
task.set("judge", judge);
|
||||
task.set("remoteJudgeProblem", remoteJudgeProblem);
|
||||
task.set("token", token);
|
||||
task.set("isContest", isContest);
|
||||
task.set("tryAgainNum", tryAgainNum);
|
||||
task.set("isHasSubmitIdRemoteReJudge", isHasSubmitIdRemoteReJudge);
|
||||
try {
|
||||
boolean isOk;
|
||||
if (isContest){
|
||||
if (isContest) {
|
||||
isOk = redisUtils.llPush(Constants.Queue.CONTEST_REMOTE_JUDGE_WAITING_HANDLE.getName(), JSONUtil.toJsonStr(task));
|
||||
}else{
|
||||
} else {
|
||||
isOk = redisUtils.llPush(Constants.Queue.GENERAL_REMOTE_JUDGE_WAITING_HANDLE.getName(), JSONUtil.toJsonStr(task));
|
||||
}
|
||||
if (!isOk) {
|
||||
|
|
|
@ -71,25 +71,21 @@ public class RemoteJudgeReceiver extends AbstractReceiver {
|
|||
Judge judge = task.get("judge", Judge.class);
|
||||
String token = task.getStr("token");
|
||||
String remoteJudgeProblem = task.getStr("remoteJudgeProblem");
|
||||
Integer tryAgainNum = task.getInt("tryAgainNum");
|
||||
Boolean isHasSubmitIdRemoteReJudge = task.getBool("isHasSubmitIdRemoteReJudge");
|
||||
String remoteOJName = remoteJudgeProblem.split("-")[0].toUpperCase();
|
||||
|
||||
dispatchRemoteJudge(judge,
|
||||
token,
|
||||
remoteJudgeProblem,
|
||||
tryAgainNum,
|
||||
isHasSubmitIdRemoteReJudge,
|
||||
remoteOJName);
|
||||
}
|
||||
|
||||
private void dispatchRemoteJudge(Judge judge, String token, String remoteJudgeProblem,
|
||||
Integer tryAgainNum,
|
||||
Boolean isHasSubmitIdRemoteReJudge, String remoteOJName) {
|
||||
|
||||
ToJudge toJudge = new ToJudge();
|
||||
toJudge.setJudge(judge)
|
||||
.setTryAgainNum(tryAgainNum)
|
||||
.setToken(token)
|
||||
.setRemoteJudgeProblem(remoteJudgeProblem);
|
||||
|
||||
|
|
|
@ -29,17 +29,16 @@ public class JudgeDispatcher {
|
|||
@Autowired
|
||||
private JudgeReceiver judgeReceiver;
|
||||
|
||||
public void sendTask(Judge judge, String token, Boolean isContest, Integer tryAgainNum) {
|
||||
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);
|
||||
task.set("tryAgainNum", tryAgainNum);
|
||||
try {
|
||||
boolean isOk;
|
||||
if (isContest){
|
||||
if (isContest) {
|
||||
isOk = redisUtils.llPush(Constants.Queue.CONTEST_JUDGE_WAITING.getName(), JSONUtil.toJsonStr(task));
|
||||
}else{
|
||||
} else {
|
||||
isOk = redisUtils.llPush(Constants.Queue.GENERAL_JUDGE_WAITING.getName(), JSONUtil.toJsonStr(task));
|
||||
}
|
||||
if (!isOk) {
|
||||
|
|
|
@ -39,7 +39,8 @@ public class JudgeReceiver extends AbstractReceiver {
|
|||
|
||||
@Override
|
||||
public String getTaskByRedis(String queue) {
|
||||
if (redisUtils.lGetListSize(queue) > 0) {
|
||||
long size = redisUtils.lGetListSize(queue);
|
||||
if (size > 0) {
|
||||
return (String) redisUtils.lrPop(queue);
|
||||
} else {
|
||||
return null;
|
||||
|
@ -51,13 +52,11 @@ public class JudgeReceiver extends AbstractReceiver {
|
|||
JSONObject task = JSONUtil.parseObj(taskJsonStr);
|
||||
Judge judge = task.get("judge", Judge.class);
|
||||
String token = task.getStr("token");
|
||||
Integer tryAgainNum = task.getInt("tryAgainNum");
|
||||
// 调用判题服务
|
||||
dispatcher.dispatcher("judge", "/judge", new ToJudge()
|
||||
.setJudge(judge)
|
||||
.setToken(token)
|
||||
.setRemoteJudgeProblem(null)
|
||||
.setTryAgainNum(tryAgainNum));
|
||||
.setRemoteJudgeProblem(null));
|
||||
// 接着处理任务
|
||||
processWaitingTask();
|
||||
}
|
||||
|
|
|
@ -15,5 +15,5 @@ public interface ScheduleService {
|
|||
|
||||
void syncNoticeToRecentHalfYearUser();
|
||||
|
||||
void checkHalfAnHourPendingSubmission();
|
||||
void check20MPendingSubmission();
|
||||
}
|
||||
|
|
|
@ -383,8 +383,8 @@ public class ScheduleServiceImpl implements ScheduleService {
|
|||
|
||||
@Override
|
||||
@Scheduled(cron = "0 0/20 * * * ?")
|
||||
public void checkHalfAnHourPendingSubmission() {
|
||||
DateTime dateTime = DateUtil.offsetMinute(new Date(), -30);
|
||||
public void check20MPendingSubmission() {
|
||||
DateTime dateTime = DateUtil.offsetMinute(new Date(), -15);
|
||||
String strTime = DateFormatUtils.format(dateTime, "yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
QueryWrapper<Judge> judgeQueryWrapper = new QueryWrapper<>();
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import top.hcode.hoj.common.result.CommonResult;
|
||||
import top.hcode.hoj.pojo.dto.ToJudgeDto;
|
||||
|
@ -34,6 +35,7 @@ import java.util.List;
|
|||
* @since 2020-10-23
|
||||
*/
|
||||
@Service
|
||||
@Slf4j(topic = "hoj")
|
||||
public class JudgeServiceImpl extends ServiceImpl<JudgeMapper, Judge> implements JudgeService {
|
||||
|
||||
@Autowired
|
||||
|
@ -59,7 +61,7 @@ public class JudgeServiceImpl extends ServiceImpl<JudgeMapper, Judge> implements
|
|||
judge.setCpid(0L).setPid(problem.getId()).setDisplayPid(problem.getProblemId());
|
||||
|
||||
// 将新提交数据插入数据库
|
||||
judgeMapper.insert(judge);
|
||||
saveOrUpdate(judge);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -106,9 +106,9 @@ public class RejudgeServiceImpl implements RejudgeService {
|
|||
Problem problem = problemService.getById(judge.getPid());
|
||||
if (problem.getIsRemote()) { // 如果是远程oj判题
|
||||
remoteJudgeDispatcher.sendTask(judge, judgeToken, problem.getProblemId(),
|
||||
isContestSubmission, 1, hasSubmitIdRemoteRejudge);
|
||||
isContestSubmission, hasSubmitIdRemoteRejudge);
|
||||
} else {
|
||||
judgeDispatcher.sendTask(judge, judgeToken, isContestSubmission, 1);
|
||||
judgeDispatcher.sendTask(judge, judgeToken, isContestSubmission);
|
||||
}
|
||||
return CommonResult.successResponse(judge, "重判成功!该提交已进入判题队列!");
|
||||
} else {
|
||||
|
@ -157,13 +157,13 @@ public class RejudgeServiceImpl implements RejudgeService {
|
|||
for (Judge judge : rejudgeList) {
|
||||
// 进入重判队列,等待调用判题服务
|
||||
remoteJudgeDispatcher.sendTask(judge, judgeToken, problem.getProblemId(),
|
||||
judge.getCid() != 0, 1,
|
||||
judge.getCid() != 0,
|
||||
isHasSubmitIdRemoteRejudge(judge.getVjudgeSubmitId(), idMapStatus.get(judge.getSubmitId())));
|
||||
}
|
||||
} else {
|
||||
for (Judge judge : rejudgeList) {
|
||||
// 进入重判队列,等待调用判题服务
|
||||
judgeDispatcher.sendTask(judge, judgeToken, judge.getCid() != 0, 1);
|
||||
judgeDispatcher.sendTask(judge, judgeToken, judge.getCid() != 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ public class JudgeController {
|
|||
judge.setStatus(Constants.Judge.STATUS_COMPILING.getStatus()); // 标志该判题过程进入编译阶段
|
||||
// 写入当前判题服务的名字
|
||||
judge.setJudger(name);
|
||||
boolean updateResult = judgeService.saveOrUpdate(judge);
|
||||
boolean updateResult = judgeService.updateById(judge);
|
||||
if (!updateResult) { // 出错并不影响主要业务逻辑,可以稍微记录一下即可。
|
||||
log.error("修改Judge表失效--------->{}", "修改提交评判为编译中出错");
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ public class JudgeStrategy {
|
|||
|
||||
// 更新状态为评测数据中
|
||||
judge.setStatus(Constants.Judge.STATUS_JUDGING.getStatus());
|
||||
judgeService.saveOrUpdate(judge);
|
||||
judgeService.updateById(judge);
|
||||
// 开始测试每个测试点
|
||||
List<JSONObject> allCaseResultList = judgeRun.judgeAllCase(judge.getSubmitId(),
|
||||
problem,
|
||||
|
|
|
@ -45,9 +45,6 @@ public class ToJudge implements Serializable {
|
|||
@ApiModelProperty("调用判题机的port")
|
||||
private Integer judgeServerPort;
|
||||
|
||||
@ApiModelProperty("重新尝试的次数,40次重新调用判题机依旧失败,直接判为提交失败!")
|
||||
private Integer tryAgainNum;
|
||||
|
||||
/**
|
||||
* VJ判題辅助选择判题机序号使用
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue