Skip to content

Commit

Permalink
More debugging for #89
Browse files Browse the repository at this point in the history
  • Loading branch information
Antony1060 committed Jan 3, 2025
1 parent 5193897 commit 9d07969
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/backend/src/lib/evaluation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ export const beginEvaluation = async (
await Promise.all([
Database.insertInto("submissions", newSubmission),
updateContestMember(problemDetails.problemId, user.id, score),
]);
]).catch((error) => Logger.error("submission store failed: ", error + ""));

// I know I can put this in Promise.all, but it needs to be removed
// from redis after we have successfully stored it in the database
Expand Down
17 changes: 16 additions & 1 deletion apps/backend/src/lib/evaluation_rs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,32 @@ const convertSuccessfulEvaluationToEvaluationResult = (
const PendingListeners: Record<number, (response: SuccessfulEvaluationRS) => void> = {};

export const subscribeToEvaluatorPubSub = async () => {
setInterval(() => {
Redis.publish(Globals.evaluatorRedisPubSubChannel, "heartbeat");
}, 60 * 1000);

const subscriber = Redis.duplicate();

await subscriber.connect();

await subscriber.subscribe(Globals.evaluatorRedisPubSubChannel, (message) => {
if (message === "heartbeat") return;

try {
const parsed = JSON.parse(message);

const valid = CompiledSuccessfulEvaluationSchema.Check(parsed);

if (!valid || !PendingListeners[parsed.evaluation_id]) return;
if (!valid) {
Logger.error(
"failed validating evaluator response: " +
JSON.stringify(CompiledSuccessfulEvaluationSchema.Errors)
);

return;
}

if (!PendingListeners[parsed.evaluation_id]) return;

PendingListeners[parsed.evaluation_id](parsed as SuccessfulEvaluationRS);
delete PendingListeners[parsed.evaluation_id];
Expand Down

0 comments on commit 9d07969

Please sign in to comment.