Skip to content

Commit 893c78f

Browse files
committed
Merge branch 'master' into delete-user
2 parents cb1639c + 10b2e64 commit 893c78f

39 files changed

+751
-494
lines changed

api_gateway/src/proxy/service_addresses.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ export const questionServiceUrl = isLocal ? "http://localhost:8080" : "http://qu
55
export const userServiceHostUrl = isLocal ? "http://localhost:8081" : "http://user-service:8081/";
66
export const matchServiceHostUrl = isLocal ? "http://localhost:8082" : "http://matching-service:8082"
77
export const collabServiceHostUrl = isLocal ? "http://localhost:8083" : "http://collab-service:8083"
8-
export const executionServiceHostUrl = isLocal ? "http://localhost:8090" : "http://code-execution:8090";
8+
export const executionServiceHostUrl = isLocal ? "http://localhost:8090" : "http://code-execution:8090/";

code_execution/Dockerfile.prod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ WORKDIR /usr/src/app
1313
COPY package*.json ./
1414
RUN npm ci --only=production
1515
COPY --from=builder /app/dist ./dist
16+
EXPOSE 8090
1617

1718
# Command to run the application
1819
CMD ["npm", "run", "serve"]

code_execution/src/executor_client.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import axios from "axios";
22
import { createBatchSubmission, getQnStdInOut } from "./testcases";
33
import { callbacks, langToId } from "./shared";
44
import { judge0Result, judge0submission, submissionResult } from "./types";
5+
import { submitSubmission } from "./submission_client";
56

6-
const JUDGE_API_URL = "https://judge0-ce.p.rapidapi.com"; //"http://judge0-server:2358/submissions";
7+
const JUDGE_API_URL = "http://peerprep-g10.com:2358"; //"https://judge0-ce.p.rapidapi.com";
78
const API_KEY = process.env.JUDGE0_API_KEY;
89

910
async function submitIndividual(submission: judge0submission) {
@@ -13,7 +14,6 @@ async function submitIndividual(submission: judge0submission) {
1314
{
1415
headers: {
1516
"Content-Type": "application/json",
16-
"X-Rapidapi-Key": API_KEY,
1717
},
1818
params: { base64_encoded: "true" },
1919
}
@@ -29,7 +29,6 @@ async function submitCode(submission: judge0submission[]) {
2929
{
3030
headers: {
3131
"Content-Type": "application/json",
32-
"X-Rapidapi-Key": API_KEY,
3332
},
3433
params: { base64_encoded: "true" },
3534
}
@@ -52,9 +51,6 @@ function pollIndividualTillComplete(
5251
) {
5352
setTimeout(() => {
5453
const options = {
55-
headers: {
56-
"X-Rapidapi-Key": API_KEY,
57-
},
5854
params: {
5955
fields: "status",
6056
},
@@ -114,7 +110,6 @@ async function delSubmissions(tokens: string[]) {
114110
params: { fields: "status_id" },
115111
headers: {
116112
"X-Judge0-User": "Auth-Judge0-User",
117-
"X-Rapidapi-Key": API_KEY,
118113
},
119114
})
120115
)
@@ -155,8 +150,9 @@ export async function runSubmission(
155150
lang: string,
156151
qn__id: string,
157152
source_code: string,
158-
userid: string
153+
userid: number
159154
) {
155+
const submissionTime = new Date();
160156
const resDat: submissionResult = {
161157
completed: false,
162158
evaluated: 0,
@@ -190,4 +186,6 @@ export async function runSubmission(
190186

191187
resDat.verdict = resDat.verdict === "Unknown" ? "Accepted" : resDat.verdict;
192188
resDat.completed = true;
193-
}
189+
190+
submitSubmission(resDat.verdict, lang, qn__id, userid, source_code, submissionTime); // runs in the bg
191+
}

code_execution/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ app.get("/api/code/result/:token", async (req, res) => {
3838
return res.status(400).json({ error: "id not found" });
3939
}
4040

41-
res.json(response);
41+
res.status(200).json(response);
4242
} catch (error) {
4343
console.error(error);
4444
res.status(500).json({ error: "An error occurred" });

code_execution/src/shared.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ export const callbacks: callbackMapping = {};
44

55
export const langToId: { [key: string]: number } = {
66
"c++17": 76,
7-
"python3": 92,
8-
"java": 91,
9-
}
7+
python3: 71,
8+
java: 62,
9+
};
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import axios from "axios";
2+
import { judge0Result, submissionResult } from "./types";
3+
4+
type Question = {
5+
id: number;
6+
_id: string;
7+
title: string;
8+
description: string;
9+
topics: string[];
10+
difficulty: number;
11+
};
12+
13+
const fetchQn = async (id: string) => {
14+
const response = await axios.get<Question>(
15+
`http://question-service:8080/api/questions/${id}`
16+
);
17+
return response.data;
18+
};
19+
20+
export const submitSubmission = async (
21+
verdict: string,
22+
language: string,
23+
qid: string,
24+
userId: number,
25+
sourceCode: string,
26+
time: Date
27+
) => {
28+
const question = await fetchQn(qid);
29+
const submission = {
30+
question__id: question._id,
31+
userId: userId,
32+
questionTitle: question.title,
33+
questionId: question.id,
34+
difficulty: question.difficulty,
35+
topics: question.topics,
36+
verdict: verdict,
37+
sourceCode: sourceCode,
38+
language: language,
39+
answeredAt: time.toISOString(),
40+
};
41+
await axios.post(
42+
`http://user-service:8081/api/users/${userId}/addquestions`,
43+
submission
44+
);
45+
};

docker-compose.yml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -150,23 +150,6 @@ services:
150150
- "${PG_PORT}:5432"
151151
volumes:
152152
- postgres_data:/var/lib/postgresql/data/
153-
154-
155-
rabbitmq:
156-
image: rabbitmq:3-management
157-
container_name: rabbitmq
158-
environment:
159-
- RABBITMQ_DEFAULT_USER=guest
160-
- RABBITMQ_DEFAULT_PASS=guest
161-
ports:
162-
- "5672:5672"
163-
- "15672:15672"
164-
healthcheck:
165-
test: rabbitmq-diagnostics -q ping
166-
interval: 30s
167-
timeout: 30s
168-
retries: 5
169-
start_period: 30s
170153

171154
redis:
172155
container_name: redis

docker_compose_dev.yml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -127,22 +127,6 @@ services:
127127
volumes:
128128
- postgres_data:/var/lib/postgresql/data/
129129

130-
rabbitmq:
131-
image: rabbitmq:3-management
132-
container_name: rabbitmq
133-
environment:
134-
- RABBITMQ_DEFAULT_USER=guest
135-
- RABBITMQ_DEFAULT_PASS=guest
136-
ports:
137-
- "5672:5672"
138-
- "15672:15672"
139-
healthcheck:
140-
test: rabbitmq-diagnostics -q ping
141-
interval: 30s
142-
timeout: 30s
143-
retries: 5
144-
start_period: 30s
145-
146130
redis:
147131
container_name: redis
148132
image: redis:7

frontend/src/api/code.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export async function submitCodeForExecution(data_payload: any) {
77
}
88

99
export async function getExecutionResult(token : string) {
10-
const res = await apiGatewayClient.post(`/api/code/result/${token}`);
10+
const res = await apiGatewayClient.get(`/api/code/result/${token}`);
1111

1212
return res;
1313
}

frontend/src/api/gateway.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ export const apiGatewayClient = axios.create({
77

88

99
export const wsMatchMakeURL = process.env.NODE_ENV === 'production'? 'http://peerprep-g10.com:7999' : 'http://localhost:7999'
10-
export const wsCollabUrl = process.env.NODE_ENV === 'production'? 'ws://peerprep-g10.com:7998' :'ws://localhost:7998'
10+
export const wsCollabUrl = process.env.NODE_ENV === 'production'? 'ws://peerprep-g10.com:8083' :'ws://localhost:8083'

0 commit comments

Comments
 (0)