Skip to content

Commit 3fd5752

Browse files
authored
Merge branch 'staging' into titus/fix-local-storage-bug
2 parents fdce97a + 7d931ee commit 3fd5752

File tree

27 files changed

+602
-265
lines changed

27 files changed

+602
-265
lines changed

.github/workflows/test.yml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
steps:
2020
- name: Checkout repository
2121
uses: actions/checkout@v2
22-
22+
2323
- name: Set up .env
2424
env:
2525
QUESTION_FIREBASE_CREDENTIAL_PATH: ${{ vars.QUESTION_SERVICE_FIREBASE_CREDENTIAL_PATH }}
@@ -30,7 +30,7 @@ jobs:
3030
echo "FIREBASE_CREDENTIAL_PATH=$QUESTION_FIREBASE_CREDENTIAL_PATH" >> .env
3131
echo "JWT_SECRET=$JWT_SECRET" >> .env
3232
echo "EXECUTION_SERVICE_URL=$EXECUTION_SERVICE_URL" >> .env
33-
33+
3434
- name: Set up credentials
3535
env:
3636
QUESTION_FIREBASE_JSON: ${{ secrets.QUESTION_SERVICE_FIREBASE_CREDENTIAL }}
@@ -41,8 +41,8 @@ jobs:
4141
4242
- name: Setup Go
4343
uses: actions/setup-go@v5
44-
with:
45-
go-version: '1.23.x'
44+
with:
45+
go-version: "1.23.x"
4646

4747
- name: Install Go dependencies
4848
run: |
@@ -51,7 +51,7 @@ jobs:
5151
5252
- name: Install firebase tools
5353
run: curl -sL firebase.tools | bash
54-
54+
5555
- name: Run Go tests with Firebase emulator
5656
run: firebase emulators:exec --only firestore 'cd ./apps/question-service; go test -v ./tests'
5757

@@ -66,11 +66,11 @@ jobs:
6666
run: |
6767
cd ./apps/frontend
6868
cp .env.example .env
69-
69+
7070
- name: Set up Node.js
7171
uses: actions/setup-node@v2
7272
with:
73-
node-version: '22'
73+
node-version: "22"
7474

7575
- name: Install pnpm
7676
run: npm i -g pnpm
@@ -117,6 +117,7 @@ jobs:
117117
EXECUTION_SERVICE_PORT: ${{ vars.EXECUTION_SERVICE_PORT }}
118118
MATCHING_SERVICE_TIMEOUT: ${{ vars.MATCHING_SERVICE_TIMEOUT }}
119119
REDIS_URL: ${{ vars.REDIS_URL }}
120+
RABBITMQ_URL: ${{ vars.RABBITMQ_URL }}
120121
QUESTION_SERVICE_GRPC_URL: ${{ vars.QUESTION_SERVICE_GPRC_URL }}
121122
run: |
122123
cd ./apps/frontend
@@ -147,11 +148,13 @@ jobs:
147148
cd ../history-service
148149
echo "FIREBASE_CREDENTIAL_PATH=$HISTORY_FIREBASE_CREDENTIAL_PATH" >> .env
149150
echo "PORT=$HISTORY_SERVICE_PORT" >> .env
150-
151+
echo "RABBITMQ_URL=$RABBITMQ_URL" >> .env
152+
151153
cd ../execution-service
152154
echo "FIREBASE_CREDENTIAL_PATH=$EXECUTION_FIREBASE_CREDENTIAL_PATH" >> .env
153155
echo "PORT=$EXECUTION_SERVICE_PORT" >> .env
154156
echo "HISTORY_SERVICE_URL=$HISTORY_SERVICE_URL" >> .env
157+
echo "RABBITMQ_URL=$RABBITMQ_URL" >> .env
155158
156159
cd ../signalling-service
157160
echo "PORT=$SIGNALLING_SERVICE_PORT" >> .env
@@ -170,7 +173,7 @@ jobs:
170173
171174
cd ../history-service
172175
echo "$HISTORY_FIREBASE_JSON" > "./$HISTORY_FIREBASE_CREDENTIAL_PATH"
173-
176+
174177
cd ../execution-service
175178
echo "$EXECUTION_FIREBASE_JSON" > "./$EXECUTION_FIREBASE_CREDENTIAL_PATH"
176179

apps/docker-compose.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ services:
6868
- apps_network
6969
volumes:
7070
- ./history-service:/history-service
71-
71+
depends_on:
72+
- rabbitmq
73+
7274
signalling-service:
7375
build:
7476
context: ./signalling-service
@@ -95,6 +97,8 @@ services:
9597
volumes:
9698
- ./execution-service:/execution-service
9799
- /var/run/docker.sock:/var/run/docker.sock
100+
depends_on:
101+
- rabbitmq
98102

99103
redis:
100104
image: redis:latest
@@ -104,6 +108,19 @@ services:
104108
- 6379:6379
105109
container_name: redis-container
106110

111+
rabbitmq:
112+
image: rabbitmq:3-management
113+
networks:
114+
- apps_network
115+
ports:
116+
- 5672:5672 # Port for RabbitMQ message broker
117+
- 15672:15672 # Port for RabbitMQ Management UI
118+
environment:
119+
RABBITMQ_DEFAULT_USER: guest
120+
RABBITMQ_DEFAULT_PASS: guest
121+
volumes:
122+
- rabbitmq_data:/var/lib/rabbitmq
123+
107124
python-sandbox:
108125
build:
109126
context: ./execution-service/execution/python
@@ -114,3 +131,8 @@ services:
114131

115132
networks:
116133
apps_network:
134+
135+
volumes:
136+
# Mounts a volume for RabbitMQ data persistence.
137+
# This ensures that data is not lost when the container is restarted or removed.
138+
rabbitmq_data:

apps/execution-service/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ PORT=8083
33

44
# If you are NOT USING docker, use the below variables
55
# HISTORY_SERVICE_URL=http://localhost:8082/
6+
# RABBITMQ_URL=amqp://guest:guest@localhost:5672/
67

78
# If you are USING docker, use the below variables
89
HISTORY_SERVICE_URL=http://history-service:8082/
10+
RABBITMQ_URL=amqp://guest:guest@rabbitmq:5672/

apps/execution-service/README.md

Lines changed: 74 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,32 @@ go run main.go
2020

2121
The server will be available at http://localhost:8083.
2222

23-
## Running the Application via Docker
23+
### Setting up message queue with RabbitMQ
24+
25+
A message queue is used to pass submission results asynchronously from the execution-service to the history-service.
26+
27+
1. In order to do so, we can run the following command to set up a docker container for RabbitMQ:
28+
29+
```bash
30+
docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management
31+
```
32+
33+
2. Then we can run the execution-service:
34+
35+
```bash
36+
go run main.go
37+
```
38+
39+
3. We can run the history-service by changing our directory and running the same command:
40+
41+
```bash
42+
cd ../history-service
43+
go run main.go
44+
```
45+
46+
To view more details on the RabbitMQ queue, we can go to `localhost:15672`, and login using `guest` as the username and password.
47+
48+
### Running the Application via Docker
2449

2550
To run the application via Docker, run the following command:
2651

@@ -74,10 +99,10 @@ The following json format will be returned:
7499

75100
```json
76101
[
77-
{
78-
"input":"hello",
79-
"expected":"olleh"
80-
}
102+
{
103+
"input": "hello",
104+
"expected": "olleh"
105+
}
81106
]
82107
```
83108

@@ -98,16 +123,16 @@ The following json format will be returned:
98123

99124
```json
100125
{
101-
"visibleTestResults":[
126+
"visibleTestResults": [
102127
{
103-
"input":"hello",
104-
"expected":"olleh",
105-
"actual":"olleh",
106-
"passed":true,
107-
"error":""
128+
"input": "hello",
129+
"expected": "olleh",
130+
"actual": "olleh",
131+
"passed": true,
132+
"error": ""
108133
}
109134
],
110-
"customTestResults":null
135+
"customTestResults": null
111136
}
112137
```
113138

@@ -127,29 +152,29 @@ The following json format will be returned:
127152

128153
```json
129154
{
130-
"visibleTestResults":[
155+
"visibleTestResults": [
131156
{
132-
"input":"hello",
133-
"expected":"olleh",
134-
"actual":"olleh",
135-
"passed":true,
136-
"error":""
157+
"input": "hello",
158+
"expected": "olleh",
159+
"actual": "olleh",
160+
"passed": true,
161+
"error": ""
137162
}
138163
],
139-
"customTestResults":[
164+
"customTestResults": [
140165
{
141-
"input":"Hannah",
142-
"expected":"hannaH",
143-
"actual":"hannaH",
144-
"passed":true,
145-
"error":""
166+
"input": "Hannah",
167+
"expected": "hannaH",
168+
"actual": "hannaH",
169+
"passed": true,
170+
"error": ""
146171
},
147172
{
148-
"input":"abcdefg",
149-
"expected":"gfedcba",
150-
"actual":"gfedcba",
151-
"passed":true,
152-
"error":""
173+
"input": "abcdefg",
174+
"expected": "gfedcba",
175+
"actual": "gfedcba",
176+
"passed": true,
177+
"error": ""
153178
}
154179
]
155180
}
@@ -178,40 +203,40 @@ The following json format will be returned:
178203

179204
```json
180205
{
181-
"visibleTestResults":[
206+
"visibleTestResults": [
182207
{
183-
"input":"hello",
184-
"expected":"olleh",
185-
"actual":"olleh",
186-
"passed":true,
187-
"error":""
208+
"input": "hello",
209+
"expected": "olleh",
210+
"actual": "olleh",
211+
"passed": true,
212+
"error": ""
188213
}
189214
],
190-
"hiddenTestResults":{
191-
"passed":2,
192-
"total":2
215+
"hiddenTestResults": {
216+
"passed": 2,
217+
"total": 2
193218
},
194-
"status":"Accepted"
219+
"status": "Accepted"
195220
}
196221
```
197222

198223
If compilation error exists or any of the tests (visible and hidden) fails, status "Attempted" will be returned:
199224

200225
```json
201226
{
202-
"visibleTestResults":[
227+
"visibleTestResults": [
203228
{
204-
"input":"hello",
205-
"expected":"olleh",
206-
"actual":"",
207-
"passed":false,
208-
"error":"Command execution failed: Traceback (most recent call last):\n File \"/tmp/4149249165.py\", line 2, in \u003cmodule\u003e\n prit(name[::-1])\n ^^^^\nNameError: name 'prit' is not defined. Did you mean: 'print'?\n: %!w(*exec.ExitError=\u0026{0x4000364678 []})"
229+
"input": "hello",
230+
"expected": "olleh",
231+
"actual": "",
232+
"passed": false,
233+
"error": "Command execution failed: Traceback (most recent call last):\n File \"/tmp/4149249165.py\", line 2, in \u003cmodule\u003e\n prit(name[::-1])\n ^^^^\nNameError: name 'prit' is not defined. Did you mean: 'print'?\n: %!w(*exec.ExitError=\u0026{0x4000364678 []})"
209234
}
210235
],
211-
"hiddenTestResults":{
212-
"passed":0,
213-
"total":2
236+
"hiddenTestResults": {
237+
"passed": 0,
238+
"total": 2
214239
},
215-
"status":"Attempted"
240+
"status": "Attempted"
216241
}
217242
```

apps/execution-service/execution/python/python.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func RunPythonCode(code string, input string) (string, string, error) {
1111
cmd := exec.Command(
1212
"docker", "run", "--rm",
1313
"-i", // allows for standard input to be passed in
14-
"python-sandbox",
14+
"apps-python-sandbox",
1515
"python", "-c", code,
1616
)
1717

apps/execution-service/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ require (
3131
github.com/google/uuid v1.6.0 // indirect
3232
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
3333
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
34+
github.com/rabbitmq/amqp091-go v1.10.0 // indirect
3435
go.opencensus.io v0.24.0 // indirect
3536
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 // indirect
3637
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect

apps/execution-service/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwA
8585
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
8686
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
8787
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
88+
github.com/rabbitmq/amqp091-go v1.10.0 h1:STpn5XsHlHGcecLmMFCtg7mqq0RnD+zFr4uzukfVhBw=
89+
github.com/rabbitmq/amqp091-go v1.10.0/go.mod h1:Hy4jKW5kQART1u+JkDTF9YYOQUHXqMuhrgxOEeS7G4o=
8890
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
8991
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
9092
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=

0 commit comments

Comments
 (0)