Skip to content

Commit 5ac751a

Browse files
committed
Fix collab bug
2 parents a7013c5 + ce53139 commit 5ac751a

File tree

10 files changed

+58
-26
lines changed

10 files changed

+58
-26
lines changed

kubernetes/collab-service-service.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ spec:
99
- protocol: TCP
1010
port: 4000
1111
targetPort: 4000
12-
nodePort: 31000
13-
type: NodePort
12+
#nodePort: 31000
13+
type: ClusterIP

kubernetes/matching-service-api-deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ spec:
1414
containers:
1515
- name: matching-service-api
1616
image: distractedcat/matching-service-api:1.0.0
17-
imagePullPolicy: IfNotPresent
17+
imagePullPolicy: Always
1818
env:
1919
- name: PORT
2020
value: :9200

kubernetes/matching-service-deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ spec:
1414
containers:
1515
- name: matching-service
1616
image: distractedcat/matching-service:1.0.0
17-
imagePullPolicy: IfNotPresent
17+
imagePullPolicy: Always
1818
env:
1919
- name: RABBIT_URI
2020
value: amqp://grp14:grp14@rabbitmq/

kubernetes/nginx-deployment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ spec:
1515
containers:
1616
- name: nginx
1717
image: distractedcat/nginx:1.0.0
18+
imagePullPolicy: Always
1819
ports:
1920
- containerPort: 80

kubernetes/peerprep-deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ spec:
2727
- name: NEXT_PUBLIC_NGINX
2828
value: http://nginx:80
2929
- name: NEXT_PUBLIC_COLLAB
30-
value: ws://127.0.0.1/37919
30+
value: collab
3131
- name: DEV_ENV
3232
value: not
3333
ports:

matching-service-api/models/producer_queue.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package models
22

33
import (
44
rabbit "github.com/streadway/amqp"
5+
"log"
6+
"time"
57
)
68

79
type ProducerQueue struct {
@@ -12,13 +14,22 @@ type ProducerQueue struct {
1214
}
1315

1416
func InitialiseQueue(URI string) (*ProducerQueue, error) {
15-
connection, err := rabbit.Dial(URI)
17+
var connection *rabbit.Connection
18+
var err error
19+
20+
for i := 0; i < 10; i++ {
21+
connection, err = rabbit.Dial(URI)
22+
if err == nil {
23+
break
24+
}
25+
log.Printf("Could not establish connection to RabbitMQ, retrying in 5 seconds... (%d/10)\n", i+1)
26+
time.Sleep(5 * time.Second)
27+
}
1628

1729
if err != nil {
1830
return nil, err
1931
}
2032

21-
2233
channel, err := connection.Channel()
2334

2435
if err != nil {

matching-service/main.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"log"
55
"os"
6+
"time"
67

78
"matching-service/consumer"
89
models "matching-service/models"
@@ -57,15 +58,23 @@ func main() {
5758
log.Fatal("No Rabbit URI found in environment variables")
5859
}
5960

60-
connection, err := rabbit.Dial(URI)
61-
61+
var connection *rabbit.Connection
62+
var err error
63+
64+
for i := 0; i < 10; i++ {
65+
connection, err = rabbit.Dial(URI)
66+
if err == nil {
67+
break
68+
}
69+
log.Printf("Could not establish connection to RabbitMQ, retrying in 5 seconds... (%d/10)\n", i+1)
70+
time.Sleep(5 * time.Second)
71+
}
72+
6273
if err != nil {
63-
log.Fatal("Could not establish connection to RabbitMQ" + err.Error())
74+
log.Fatal("Could not establish connection to RabbitMQ after 10 attempts: " + err.Error())
6475
}
6576

6677
defer connection.Close()
67-
68-
6978

7079
channel, err := connection.Channel()
7180

nginx/nginx.conf

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ http {
4040
server storage-blob-api:9300;
4141
}
4242

43-
# upstream collab {
44-
# server collab:4000;
45-
# }
43+
upstream collab {
44+
server collab:4000;
45+
}
4646

4747
server {
4848
listen 80;
@@ -52,6 +52,9 @@ http {
5252
proxy_set_header X-Real-IP $remote_addr;
5353
proxy_set_header X-Forwarded-Proto $scheme;
5454
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
55+
proxy_http_version 1.1;
56+
proxy_set_header Upgrade $http_upgrade;
57+
proxy_set_header Connection "upgrade";
5558
}
5659

5760
location /users/ {
@@ -71,8 +74,16 @@ http {
7174
proxy_pass http://storage_blob_api/;
7275
}
7376

74-
# location /collab/ {
75-
# proxy_pass http://collab/;
76-
# }
77+
location /collab/ {
78+
proxy_pass http://collab/;
79+
proxy_set_header Host $host;
80+
proxy_set_header X-Real-IP $remote_addr;
81+
proxy_set_header X-Forwarded-Proto $scheme;
82+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
83+
proxy_http_version 1.1;
84+
proxy_set_header Upgrade $http_upgrade;
85+
proxy_set_header Connection "upgrade";
86+
proxy_read_timeout 86400;
87+
}
7788
}
7889
}

peerprep/components/questionpage/Matchmaking.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
import ResettingStopwatch from "../shared/ResettingStopwatch";
1818
import PeerprepDropdown from "../shared/PeerprepDropdown";
1919

20-
const QUERY_INTERVAL_MILLISECONDS = 5000;
20+
const QUERY_INTERVAL_MILLISECONDS = 1000;
2121
const TIMEOUT_MILLISECONDS = 30000;
2222

2323
const getMatchRequestTime = (): string => {

peerprep/next.config.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/** @type {import('next').NextConfig} */
2-
const nextConfig = {}
2+
const nextConfig = {};
33

44
module.exports = {
55
async rewrites() {
66
return [
77
{
8-
source: '/api/proxy', // client connects to api/proxy
8+
source: "/api/proxy", // client connects to api/proxy
99
// by default we expect NEXT_PUBLIC_COLLAB to be http://collab:4000.
1010
// double check this before using this.
11-
destination: `${process.env.NEXT_PUBLIC_COLLAB}/ws`,
12-
}
13-
]
14-
}
15-
}
11+
destination: `${process.env.NEXT_PUBLIC_NGINX}/${process.env.NEXT_PUBLIC_COLLAB}/ws`,
12+
},
13+
];
14+
},
15+
};

0 commit comments

Comments
 (0)