diff --git a/judgels-backends/judgels-server-app/src/main/java/judgels/jerahmeel/submission/programming/SubmissionResource.java b/judgels-backends/judgels-server-app/src/main/java/judgels/jerahmeel/submission/programming/SubmissionResource.java index c41e317b7..cd6c8260d 100644 --- a/judgels-backends/judgels-server-app/src/main/java/judgels/jerahmeel/submission/programming/SubmissionResource.java +++ b/judgels-backends/judgels-server-app/src/main/java/judgels/jerahmeel/submission/programming/SubmissionResource.java @@ -10,12 +10,14 @@ import static judgels.service.ServiceUtils.checkFound; import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import io.dropwizard.hibernate.UnitOfWork; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; import javax.inject.Inject; import javax.ws.rs.Consumes; import javax.ws.rs.DefaultValue; @@ -287,7 +289,7 @@ public void regradeSubmission( @POST @Path("/regrade") - @UnitOfWork + @UnitOfWork(transactional = false) public void regradeSubmissions( @HeaderParam(AUTHORIZATION) AuthHeader authHeader, @QueryParam("containerJid") Optional containerJid, @@ -298,20 +300,24 @@ public void regradeSubmissions( String actorJid = actorChecker.check(authHeader); checkAllowed(submissionRoleChecker.canManage(actorJid)); + Map configsMap = new HashMap<>(); + for (int pageNumber = 1;; pageNumber++) { List submissions = submissionStore.getSubmissions( containerJid, byUserJid(username), byProblemJid(containerJid, problemJid, problemAlias), pageNumber, - PAGE_SIZE).getPage(); + 100).getPage(); if (submissions.isEmpty()) { break; } var problemJids = Lists.transform(submissions, Submission::getProblemJid); - Map configsMap = sandalphonClient.getProgrammingProblemSubmissionConfigs(problemJids); + configsMap.putAll(sandalphonClient.getProgrammingProblemSubmissionConfigs( + Sets.difference(Set.copyOf(problemJids), configsMap.keySet()))); + submissionRegrader.regradeSubmissions(submissions, configsMap); } } diff --git a/judgels-backends/judgels-server-app/src/main/java/judgels/sandalphon/submission/programming/GradingResponseProcessor.java b/judgels-backends/judgels-server-app/src/main/java/judgels/sandalphon/submission/programming/GradingResponseProcessor.java index ffb54f5be..e0eb12305 100644 --- a/judgels-backends/judgels-server-app/src/main/java/judgels/sandalphon/submission/programming/GradingResponseProcessor.java +++ b/judgels-backends/judgels-server-app/src/main/java/judgels/sandalphon/submission/programming/GradingResponseProcessor.java @@ -3,7 +3,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.dropwizard.hibernate.UnitOfWork; import java.io.IOException; -import java.time.Duration; import java.util.Optional; import judgels.gabriel.api.GradingResponse; import judgels.messaging.MessageClient; @@ -15,9 +14,6 @@ public class GradingResponseProcessor { private static final Logger LOGGER = LoggerFactory.getLogger(GradingResponseProcessor.class); - private static final int MAX_RETRIES = 3; - private static final Duration DELAY_BETWEEN_RETRIES = Duration.ofSeconds(5); - private final ObjectMapper mapper; private final SubmissionStore submissionStore; private final MessageClient messageClient; @@ -45,28 +41,13 @@ public void process(Message message) { return; } - boolean gradingExists = false; - - // it is possible that the grading model is not immediately found, because it is not flushed yet. - for (int i = 0; i < MAX_RETRIES; i++) { - Optional submission = - submissionStore.updateGrading(response.getGradingJid(), response.getResult()); - if (submission.isPresent()) { - gradingExists = true; - submissionConsumer.accept(submission.get()); - messageClient.confirmMessage(message.getId()); - break; - } - - try { - Thread.sleep(DELAY_BETWEEN_RETRIES.toMillis()); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - } - - if (!gradingExists) { + Optional submission = submissionStore.updateGrading(response.getGradingJid(), response.getResult()); + if (submission.isEmpty()) { LOGGER.error("Failed to find grading jid {}", response.getGradingJid()); + return; } + + submissionConsumer.accept(submission.get()); + messageClient.confirmMessage(message.getId()); } } diff --git a/judgels-backends/judgels-server-app/src/main/java/judgels/uriel/contest/submission/programming/ContestSubmissionResource.java b/judgels-backends/judgels-server-app/src/main/java/judgels/uriel/contest/submission/programming/ContestSubmissionResource.java index 5a82fe2b0..53aed1008 100644 --- a/judgels-backends/judgels-server-app/src/main/java/judgels/uriel/contest/submission/programming/ContestSubmissionResource.java +++ b/judgels-backends/judgels-server-app/src/main/java/judgels/uriel/contest/submission/programming/ContestSubmissionResource.java @@ -14,9 +14,11 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import io.dropwizard.hibernate.UnitOfWork; import java.util.Collections; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; @@ -318,7 +320,7 @@ public void regradeSubmission( @POST @Path("/regrade") - @UnitOfWork + @UnitOfWork(transactional = false) public void regradeSubmissions( @HeaderParam(AUTHORIZATION) AuthHeader authHeader, @QueryParam("contestJid") String contestJid, @@ -331,20 +333,24 @@ public void regradeSubmissions( Optional problemJid = byProblemJid(contestJid, problemAlias); + Map configsMap = new HashMap<>(); + for (int pageNumber = 1;; pageNumber++) { List submissions = submissionStore.getSubmissions( Optional.of(contestJid), byUserJid(username), problemJid, pageNumber, - PAGE_SIZE).getPage(); + 100).getPage(); if (submissions.isEmpty()) { break; } var problemJids = Lists.transform(submissions, Submission::getProblemJid); - Map configsMap = sandalphonClient.getProgrammingProblemSubmissionConfigs(problemJids); + configsMap.putAll(sandalphonClient.getProgrammingProblemSubmissionConfigs( + Sets.difference(Set.copyOf(problemJids), configsMap.keySet()))); + submissionRegrader.regradeSubmissions(submissions, configsMap); } scoreboardIncrementalMarker.invalidateMark(contest.getJid());