@@ -5,7 +5,7 @@ const { notifyUsers } = require('../websocket/websocket');
5
5
const { v4 : uuidv4 } = require ( 'uuid' ) ;
6
6
// matchingService/fetchQuestion.js
7
7
const axios = require ( 'axios' ) ;
8
- const questionAPIUrl = 'http://localhost :3001/api/questions' ;
8
+ const questionAPIUrl = 'http://question-service :3001/api/questions' ;
9
9
10
10
11
11
// TODO: Subscribe and acknowledge messages with user info when timeout/user matched
@@ -77,15 +77,19 @@ function matchUsers(channel, msg, userId, difficulty, category) {
77
77
78
78
// Try matching with category only if no difficulty match is found
79
79
if ( waitingUsers [ criteriaKey ] . length < 2 ) {
80
- waitingUsers [ categoryKey ] . push ( { userId, msg, channel } ) ;
81
- console . log ( `Fallback: User ${ userId } added to ${ categoryKey } . Waiting list: ${ waitingUsers [ categoryKey ] . length } ` ) ;
82
- if ( waitingUsers [ categoryKey ] . length >= 2 ) {
83
- const matchedUsers = waitingUsers [ categoryKey ] . splice ( 0 , 2 ) ;
84
- removeMatchedUsersFromOtherLists ( matchedUsers , categoryKey ) ;
85
- console . log ( "waitingusers after lenient matching: " , waitingUsers )
86
- notifyMatch ( channel , matchedUsers , category , difficulty ) ;
87
- return true ;
88
- }
80
+ // Add a 5-second delay before adding the user to waitingUsers[categoryKey]
81
+ setTimeout ( ( ) => {
82
+ waitingUsers [ categoryKey ] . push ( { userId, msg, channel } ) ;
83
+ console . log ( `Fallback: User ${ userId } added to ${ categoryKey } . Waiting list: ${ waitingUsers [ categoryKey ] . length } ` ) ;
84
+
85
+ if ( waitingUsers [ categoryKey ] . length >= 2 ) {
86
+ const matchedUsers = waitingUsers [ categoryKey ] . splice ( 0 , 2 ) ;
87
+ removeMatchedUsersFromOtherLists ( matchedUsers , categoryKey ) ;
88
+ console . log ( "waitingusers after lenient matching: " , waitingUsers )
89
+ notifyMatch ( channel , matchedUsers , category , difficulty ) ;
90
+ return true ;
91
+ }
92
+ } , 5000 ) ; // 5-second delay
89
93
}
90
94
91
95
return false ;
0 commit comments