Skip to content

Commit 8559e67

Browse files
committed
feature/match: Add request ID to prep for cancellation logic
Signed-off-by: SeeuSim <[email protected]>
1 parent bac69c4 commit 8559e67

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

backend/matching/src/controllers/match-request.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,24 @@ export const matchRequestController = async (req: Request, res: Response) => {
1919

2020
// TODO: Assign a proper socket to the user
2121
const socketRoom = createNotifSocket(userId);
22+
const timestamp = `${Date.now()}`;
2223

23-
// TODO: Test if room logic works and notif socket can connect
2424
// Send socket to user first for them to subscribe
2525
res
2626
.status(StatusCodes.OK)
2727
.json({
2828
socketPort: socketRoom,
29+
requestId: timestamp, // Queue ID
2930
})
3031
.end();
3132

3233
// TODO: Wait for user to connect to notif socket, or add a time buffer
3334

34-
await queueingService(redisClient, { userId, difficulty, topic, socketPort: socketRoom });
35+
await queueingService(redisClient, {
36+
userId,
37+
difficulty,
38+
topic,
39+
socketPort: socketRoom,
40+
timestamp,
41+
});
3542
};
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { IPoolTicket } from '@/types';
22

3-
export const getRedisPayload = (payload: Omit<IPoolTicket, 'timestamp'>) => {
3+
export const getRedisPayload = (payload: IPoolTicket) => {
44
const { topic, difficulty, ...rest } = payload;
55
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
66
const difficultyField: { difficulty: string } | {} = difficulty ? { difficulty } : {};
@@ -10,6 +10,5 @@ export const getRedisPayload = (payload: Omit<IPoolTicket, 'timestamp'>) => {
1010
? { topic: topic.join(',') }
1111
: { topic }
1212
: {};
13-
const timestamp = `${Date.now()}`;
14-
return { ...rest, ...topicField, ...difficultyField, timestamp };
13+
return { ...rest, ...topicField, ...difficultyField };
1514
};

backend/matching/src/types/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ export type IRequestMatchPayload = {
1313
export type IQueueRequest = Partial<Pick<IRequestMatchPayload, 'topic' | 'difficulty'>> &
1414
Pick<IRequestMatchPayload, 'userId'> & {
1515
socketPort: string;
16+
timestamp: string;
1617
};
1718

18-
export type IPoolTicket = IQueueRequest & {
19-
socketPort: string;
20-
timestamp: string;
21-
};
19+
export type IPoolTicket = IQueueRequest;
2220

2321
export type IRedisClient = Awaited<ReturnType<(typeof client)['connect']>>;
2422

0 commit comments

Comments
 (0)