Skip to content

Commit 61ac5cc

Browse files
committed
Merge remote-tracking branch 'origin/user-matching' into match-button
2 parents d8c53ea + 994ba1a commit 61ac5cc

File tree

11 files changed

+109
-46
lines changed

11 files changed

+109
-46
lines changed

matching-service-api/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
log
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
time="2024-10-13T11:40:53+08:00" level=info msg="Server started at time: 2024-10-13 11:40:53.9651404 +0800 +08 m=+0.020315501"
2+
time="2024-10-13T11:44:08+08:00" level=info msg="Server started at time: 2024-10-13 11:44:08.2137412 +0800 +08 m=+0.019447901"
3+
time="2024-10-13T11:45:18+08:00" level=info msg="Server started at time: 2024-10-13 11:45:18.8711385 +0800 +08 m=+0.018465501"
4+
time="2024-10-13T11:46:37+08:00" level=info msg="Server started at time: 2024-10-13 11:46:37.0114407 +0800 +08 m=+0.019357101"
5+
time="2024-10-13T11:46:49+08:00" level=info msg="request from user hello successfully published"
6+
time="2024-10-13T11:47:24+08:00" level=info msg="request from user hello successfully published"
7+
time="2024-10-13T11:52:42+08:00" level=info msg="Server started at time: 2024-10-13 11:52:42.820679 +0800 +08 m=+0.019017101"
8+
time="2024-10-13T11:52:49+08:00" level=error msg="error publishing message:Exception (504) Reason: \"channel/connection is not open\""
9+
time="2024-10-13T11:52:49+08:00" level=info msg="request from user hello successfully published"
10+
time="2024-10-13T11:54:36+08:00" level=info msg="Server started at time: 2024-10-13 11:54:36.2585996 +0800 +08 m=+0.018451501"
11+
time="2024-10-13T11:54:39+08:00" level=error msg="error publishing message:Exception (504) Reason: \"channel/connection is not open\""
12+
time="2024-10-13T11:54:39+08:00" level=info msg="request from user hello successfully published"
13+
time="2024-10-13T12:54:45+08:00" level=info msg="Server started at time: 2024-10-13 12:54:45.809209 +0800 +08 m=+0.018372701"
14+
time="2024-10-13T12:55:54+08:00" level=info msg="Server started at time: 2024-10-13 12:55:54.7209082 +0800 +08 m=+0.017350501"
15+
time="2024-10-13T12:55:59+08:00" level=info msg="request from user hello successfully published"
16+
time="2024-10-13T12:56:13+08:00" level=info msg="request from user hello successfully published"
17+
time="2024-10-15T21:16:09+08:00" level=info msg="Server started at time: 2024-10-15 21:16:09.5830829 +0800 +08 m=+0.018717201"
18+
time="2024-10-15T21:19:11+08:00" level=info msg="request from user user1 successfully published"
19+
time="2024-10-15T21:24:05+08:00" level=info msg="request from user user1 successfully published"
20+
time="2024-10-15T21:24:19+08:00" level=info msg="request from user user1 successfully published"
21+
time="2024-10-15T21:27:07+08:00" level=info msg="request from user user1 successfully published"
22+
time="2024-10-15T21:27:16+08:00" level=info msg="request from user user2 successfully published"
23+
time="2024-10-15T21:34:56+08:00" level=info msg="request from user user2 successfully published"
24+
time="2024-10-15T21:35:04+08:00" level=info msg="request from user user1 successfully published"
25+
time="2024-10-16T11:47:58+08:00" level=info msg="Server started at time: 2024-10-16 11:47:58.9097737 +0800 +08 m=+0.018180201"
26+
time="2024-10-16T11:58:13+08:00" level=info msg="request from user user1 successfully published"
27+
time="2024-10-16T11:58:19+08:00" level=info msg="request from user user2 successfully published"
28+
time="2024-10-16T12:04:09+08:00" level=info msg="request from user user1 successfully published"
29+
time="2024-10-16T12:04:12+08:00" level=info msg="request from user user2 successfully published"
30+
time="2024-10-16T12:06:43+08:00" level=info msg="request from user user2 successfully published"
31+
time="2024-10-16T12:06:47+08:00" level=info msg="request from user user1 successfully published"
32+
time="2024-10-16T12:12:09+08:00" level=info msg="request from user user1 successfully published"
33+
time="2024-10-16T12:12:14+08:00" level=info msg="request from user user2 successfully published"
34+
time="2024-10-16T12:16:10+08:00" level=info msg="request from user user1 successfully published"
35+
time="2024-10-16T12:16:15+08:00" level=info msg="request from user user2 successfully published"

matching-service-api/transport/request_handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ func HandleRequest(channel *models.ProducerQueue, logger *models.Logger) gin.Han
3030
}
3131

3232
//current time is more than 30 seconds after request time, timeout
33-
if time.Now().After(parsedTime.Add(30 * time.Second)) {
33+
if time.Now().After(parsedTime.Add(30 * time.Second).Add(-8 * time.Hour)) {
3434
logger.Log.Warn("request timeout")
35-
ctx.JSON(http.StatusRequestTimeout, "request timed out")
35+
ctx.JSON(http.StatusRequestTimeout, "request time is too old")
3636
return
3737
}
3838

matching-service/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
log

matching-service/consumer/process_request.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
//This is the logic to handle user requests.
22
//Each client is internally mapped to all the possible questions that satisfy their request.
3-
//This server stores all the mappings between each client and their potential questions(id).
43
//If another user comes where their possible questions overlap with that of another user, a random question in the intersection is selected.
54

65
package consumer
76

87
import (
9-
"context"
108
"encoding/json"
119
"fmt"
1210
"matching-service/models"
@@ -29,19 +27,12 @@ func Process(msg rabbit.Delivery, clientMappings *db.ClientMappings, roomMapping
2927
}
3028

3129
fmt.Println("success handling incoming request!")
32-
//deliver the response to the backend
33-
//TODO: to implement this
3430
if room != nil {
3531
if err := roomMappings.SendToStorageBlob(room); err != nil {
3632
return err
3733
}
3834

3935
fmt.Println("success sending to storage blob")
40-
keys, _ := roomMappings.Conn.Keys(context.Background(), "*").Result()
41-
fmt.Println(keys)
42-
result, _ := roomMappings.Conn.HGetAll(context.Background(), "user1").Result()
43-
44-
fmt.Println(len(result))
4536
}
4637

4738
return nil
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
time="2024-10-15T21:34:37+08:00" level=info msg="Beginning consumption from message queue"
2+
time="2024-10-15T21:34:37+08:00" level=info msg="Begin processing requests"
3+
time="2024-10-16T11:47:46+08:00" level=info msg="Beginning consumption from message queue"
4+
time="2024-10-16T11:47:46+08:00" level=info msg="Begin processing requests"
5+
time="2024-10-16T12:06:22+08:00" level=info msg="Beginning consumption from message queue"
6+
time="2024-10-16T12:06:22+08:00" level=info msg="Begin processing requests"
7+
time="2024-10-16T12:11:53+08:00" level=info msg="Beginning consumption from message queue"
8+
time="2024-10-16T12:11:53+08:00" level=info msg="Begin processing requests"
9+
time="2024-10-17T22:06:35+08:00" level=info msg="Beginning consumption from message queue"
10+
time="2024-10-17T22:06:35+08:00" level=info msg="Begin processing requests"
11+
time="2024-10-17T22:18:03+08:00" level=info msg="Beginning consumption from message queue"
12+
time="2024-10-17T22:18:03+08:00" level=info msg="Begin processing requests"
13+
time="2024-10-17T22:32:32+08:00" level=info msg="Beginning consumption from message queue"
14+
time="2024-10-17T22:32:32+08:00" level=info msg="Begin processing requests"
15+
time="2024-10-17T22:33:42+08:00" level=info msg="Beginning consumption from message queue"
16+
time="2024-10-17T22:33:42+08:00" level=info msg="Begin processing requests"
17+
time="2024-10-17T22:36:02+08:00" level=info msg="Beginning consumption from message queue"
18+
time="2024-10-17T22:36:02+08:00" level=info msg="Begin processing requests"
19+
time="2024-10-17T22:36:17+08:00" level=error msg="error parsing the time: parsing time \"2024-10-17 22-36-30\" as \"2006-01-02 15-04-05 +0800\": cannot parse \"\" as \" +0800\""
20+
time="2024-10-17T22:39:31+08:00" level=info msg="Beginning consumption from message queue"
21+
time="2024-10-17T22:39:31+08:00" level=info msg="Begin processing requests"
22+
time="2024-10-17T22:43:06+08:00" level=info msg="Beginning consumption from message queue"
23+
time="2024-10-17T22:43:06+08:00" level=info msg="Begin processing requests"
24+
time="2024-10-17T22:51:23+08:00" level=info msg="Beginning consumption from message queue"
25+
time="2024-10-17T22:51:23+08:00" level=info msg="Begin processing requests"

matching-service/storage/client_mappings.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (db *ClientMappings) HandleRequest(request models.IncomingRequests) (*model
121121
return nil, err
122122
}
123123

124-
expiryTime := requestTime.Add(30 * time.Second)
124+
expiryTime := requestTime.Add(30 * time.Second).Add(-8 * time.Hour)
125125
diff := int(time.Until(expiryTime).Seconds())
126126
err = db.Conn.Expire(ctx, user2, time.Duration(diff) * time.Second).Err()
127127

matching-service/storage/room_mappings.go

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ import (
1010
redis "github.com/go-redis/redis/v8"
1111
)
1212

13-
//same as client mappings, but separated for type safety
13+
// same as client mappings, but separated for type safety
1414
type RoomMappings struct {
1515
Conn *redis.Client
1616
}
1717

1818
func InitialiseRoomMappings(addr string, db_num int) *RoomMappings {
1919
conn := redis.NewClient(&redis.Options{
20-
Addr:addr,
21-
DB: db_num,
22-
})
20+
Addr: addr,
21+
DB: db_num,
22+
})
2323

2424
return &RoomMappings{
2525
Conn: conn,
@@ -40,61 +40,59 @@ func (db *RoomMappings) SendToStorageBlob(room *models.Room) error {
4040
return fmt.Errorf("error marshling topics: %s", err.Error())
4141
}
4242

43-
4443
user1_info := map[string]interface{}{
45-
"roomId": room.RoomId,
46-
"otherUser": room.User2,
44+
"roomId": room.RoomId,
45+
"otherUser": room.User2,
4746
"requestTime": room.RequestTime,
4847

49-
"title": room.Title,
50-
"titleSlug": room.TitleSlug,
48+
"title": room.Title,
49+
"titleSlug": room.TitleSlug,
5150
"difficulty": room.Difficulty,
52-
"topicTags": topics_json,
53-
"content": room.Content,
54-
"schemas": schema_json,
55-
"id": room.QuestionId,
51+
"topicTags": topics_json,
52+
"content": room.Content,
53+
"schemas": schema_json,
54+
"id": room.QuestionId,
5655
}
5756

5857
user2_info := map[string]interface{}{
59-
"roomId": room.RoomId,
60-
"otherUser": room.User1,
58+
"roomId": room.RoomId,
59+
"otherUser": room.User1,
6160
"requestTime": room.RequestTime,
6261

63-
"title": room.Title,
64-
"titleSlug": room.TitleSlug,
62+
"title": room.Title,
63+
"titleSlug": room.TitleSlug,
6564
"difficulty": room.Difficulty,
66-
"topicTags": topics_json,
67-
"content": room.Content,
68-
"schemas": schema_json,
69-
"id": room.QuestionId,
65+
"topicTags": topics_json,
66+
"content": room.Content,
67+
"schemas": schema_json,
68+
"id": room.QuestionId,
7069
}
7170

72-
73-
if err1 := db.Conn.HSet(ctx, room.User1, user1_info).Err(); err1 != nil {
71+
if err1 := db.Conn.HSet(ctx, room.User1, user1_info).Err(); err1 != nil {
7472
return fmt.Errorf("error setting user1's room to storage: %s", err1.Error())
7573
}
7674

77-
78-
if err2 := db.Conn.HSet(ctx, room.User2, user2_info).Err(); err2 != nil {
75+
if err2 := db.Conn.HSet(ctx, room.User2, user2_info).Err(); err2 != nil {
7976
return fmt.Errorf("error setting user2's room to storage: %s", err2.Error())
8077
}
81-
78+
8279
requestTime, err := time.Parse("2006-01-02 15-04-05", room.RequestTime)
8380

8481
if err != nil {
8582
return fmt.Errorf("error parsing the time: %s", err.Error())
8683
}
8784

88-
expiryTime := requestTime.Add(30 * time.Second)
85+
expiryTime := requestTime.Add(30 * time.Second).Add(-8 * time.Hour)
86+
8987
diff := int(time.Until(expiryTime).Seconds())
90-
91-
if err1 := db.Conn.Expire(ctx, room.User1, time.Duration(diff) * time.Second).Err(); err1 != nil {
88+
89+
if err1 := db.Conn.Expire(ctx, room.User1, time.Duration(diff)*time.Second).Err(); err1 != nil {
9290
return fmt.Errorf("error setting expiry time on room data: %s", err1.Error())
9391
}
94-
95-
if err2 := db.Conn.Expire(ctx, room.User2, time.Duration(diff) * time.Second).Err(); err2 != nil {
92+
93+
if err2 := db.Conn.Expire(ctx, room.User2, time.Duration(diff)*time.Second).Err(); err2 != nil {
9694
return fmt.Errorf("error setting expiry time on room data: %s", err2.Error())
97-
}
98-
95+
}
96+
9997
return nil
100-
}
98+
}

storage-blob-api/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
log
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
time="2024-10-16T11:48:22+08:00" level=info msg="Server started running successfully"
2+
time="2024-10-16T11:48:47+08:00" level=error msg="unable to unmarshal topicTags to json: unexpected end of JSON input"
3+
time="2024-10-16T11:51:52+08:00" level=error msg="unable to unmarshal topicTags to json: unexpected end of JSON input"
4+
time="2024-10-16T11:54:34+08:00" level=info msg="Server started running successfully"
5+
time="2024-10-16T11:54:38+08:00" level=error msg="unable to unmarshal topicTags to json: unexpected end of JSON input"
6+
time="2024-10-16T11:55:04+08:00" level=info msg="Server started running successfully"
7+
time="2024-10-16T11:55:08+08:00" level=error msg="unable to unmarshal topicTags to json: unexpected end of JSON input"
8+
time="2024-10-16T11:57:16+08:00" level=info msg="Server started running successfully"
9+
time="2024-10-16T12:15:40+08:00" level=info msg="Server started running successfully"
10+
time="2024-10-16T12:16:23+08:00" level=info msg="Request handled successfully"

0 commit comments

Comments
 (0)