add judge lock
This commit is contained in:
parent
33375ee5a4
commit
ddce7a2d40
|
@ -117,11 +117,18 @@ public class JudgeController {
|
||||||
|
|
||||||
if (!isContestSubmission) { // 非比赛提交限制8秒提交一次
|
if (!isContestSubmission) { // 非比赛提交限制8秒提交一次
|
||||||
String lockKey = Constants.Account.SUBMIT_NON_CONTEST_LOCK.getCode() + userRolesVo.getUid();
|
String lockKey = Constants.Account.SUBMIT_NON_CONTEST_LOCK.getCode() + userRolesVo.getUid();
|
||||||
boolean isRestricted = redisUtils.hasKey(lockKey);
|
long count = redisUtils.incr(lockKey, 1);
|
||||||
if (isRestricted) {
|
if (count > 1) {
|
||||||
return CommonResult.errorResponse("对不起,您的提交频率过快,请稍后再尝试!", CommonResult.STATUS_FORBIDDEN);
|
return CommonResult.errorResponse("对不起,您的提交频率过快,请稍后再尝试!", CommonResult.STATUS_FORBIDDEN);
|
||||||
}
|
}
|
||||||
redisUtils.set(lockKey, 1, 8);
|
redisUtils.expire(lockKey, 8);
|
||||||
|
} else { // 比赛提交限制3秒一次
|
||||||
|
String lockKey = Constants.Account.SUBMIT_CONTEST_LOCK.getCode() + userRolesVo.getUid();
|
||||||
|
long count = redisUtils.incr(lockKey, 1);
|
||||||
|
if (count > 1) {
|
||||||
|
return CommonResult.errorResponse("对不起,您的提交频率过快,请稍后再尝试!", CommonResult.STATUS_FORBIDDEN);
|
||||||
|
}
|
||||||
|
redisUtils.expire(lockKey, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (judgeDto.getCode().length() < 50 && !judgeDto.getLanguage().contains("Py")) {
|
if (judgeDto.getCode().length() < 50 && !judgeDto.getLanguage().contains("Py")) {
|
||||||
|
|
|
@ -47,9 +47,8 @@ public class RemoteJudgeDispatcher {
|
||||||
.setStatus(Constants.Judge.STATUS_SUBMITTED_FAILED.getStatus())
|
.setStatus(Constants.Judge.STATUS_SUBMITTED_FAILED.getStatus())
|
||||||
.setErrorMessage("Please try to submit again!")
|
.setErrorMessage("Please try to submit again!")
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
remoteJudgeReceiver.processWaitingTask();
|
|
||||||
}
|
}
|
||||||
|
remoteJudgeReceiver.processWaitingTask();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("调用redis将判题纳入判题等待队列异常,此次判题任务判为系统错误--------------->", e);
|
log.error("调用redis将判题纳入判题等待队列异常,此次判题任务判为系统错误--------------->", e);
|
||||||
judgeService.failToUseRedisPublishJudge(judge.getSubmitId(), judge.getPid(), isContest);
|
judgeService.failToUseRedisPublishJudge(judge.getSubmitId(), judge.getPid(), isContest);
|
||||||
|
|
|
@ -48,10 +48,9 @@ public class JudgeDispatcher {
|
||||||
.setStatus(Constants.Judge.STATUS_SUBMITTED_FAILED.getStatus())
|
.setStatus(Constants.Judge.STATUS_SUBMITTED_FAILED.getStatus())
|
||||||
.setErrorMessage("Please try to submit again!")
|
.setErrorMessage("Please try to submit again!")
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
// 调用判题任务处理
|
|
||||||
judgeReceiver.processWaitingTask();
|
|
||||||
}
|
}
|
||||||
|
// 调用判题任务处理
|
||||||
|
judgeReceiver.processWaitingTask();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("调用redis将判题纳入判题等待队列异常,此次判题任务判为系统错误--------------->{}", e.getMessage());
|
log.error("调用redis将判题纳入判题等待队列异常,此次判题任务判为系统错误--------------->{}", e.getMessage());
|
||||||
judgeService.failToUseRedisPublishJudge(judge.getSubmitId(), judge.getPid(), isContest);
|
judgeService.failToUseRedisPublishJudge(judge.getSubmitId(), judge.getPid(), isContest);
|
||||||
|
|
|
@ -382,7 +382,7 @@ public class ScheduleServiceImpl implements ScheduleService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Scheduled(cron = "0 0/30 * * * ?")
|
@Scheduled(cron = "0 0/20 * * * ?")
|
||||||
public void checkHalfAnHourPendingSubmission() {
|
public void checkHalfAnHourPendingSubmission() {
|
||||||
DateTime dateTime = DateUtil.offsetMinute(new Date(), -30);
|
DateTime dateTime = DateUtil.offsetMinute(new Date(), -30);
|
||||||
String strTime = DateFormatUtils.format(dateTime, "yyyy-MM-dd HH:mm:ss");
|
String strTime = DateFormatUtils.format(dateTime, "yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
|
@ -159,6 +159,7 @@ public class Constants {
|
||||||
OI_RANK_CACHE("oi_rank_cache"),
|
OI_RANK_CACHE("oi_rank_cache"),
|
||||||
|
|
||||||
SUBMIT_NON_CONTEST_LOCK("submit_non_contest_lock:"),
|
SUBMIT_NON_CONTEST_LOCK("submit_non_contest_lock:"),
|
||||||
|
SUBMIT_CONTEST_LOCK("submit_contest_lock:"),
|
||||||
DISCUSSION_ADD_NUM_LOCK("discussion_add_num_lock:"),
|
DISCUSSION_ADD_NUM_LOCK("discussion_add_num_lock:"),
|
||||||
CONTEST_ADD_PRINT_LOCK("contest_add_print_lock:"),
|
CONTEST_ADD_PRINT_LOCK("contest_add_print_lock:"),
|
||||||
|
|
||||||
|
|
|
@ -582,7 +582,7 @@ public final class RedisUtils {
|
||||||
|
|
||||||
public Object lrPop(String key) {
|
public Object lrPop(String key) {
|
||||||
try {
|
try {
|
||||||
return redisTemplate.opsForList().rightPop(key, 5, TimeUnit.SECONDS);
|
return redisTemplate.opsForList().rightPop(key, 10, TimeUnit.SECONDS);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in New Issue