You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This service can be accessed both via REST API routes, and purely through websockets (via socket.Io). If you use REST, you must also send the client's socketId, so you need to retrieve it on the frontend first. If you are communicating purely via websockets, then you just need to send { username, email, category, difficulty } along with the event name of `startMatching`.
3
+
To configure the .env files, create a copy of .env.example and rename it .env.
4
+
If you edited the .env file on the root level, copy and paste it in.
4
5
5
-
To test the local implementation of this service without frontend, follow the steps below:
6
+
.env variables:
7
+
# Database Connection String Details
8
+
DATABASE_NAME=peerprepMatchingServiceDB
9
+
Should be the same as the root .env file.
6
10
7
-
1. Run `npm install` at this level (root of matching-service).
8
-
2. Configure the .env file. Edit the `DB_REQUIRE_AUTH` field in .env to be false for local.
9
-
3. Successful match events will be recorded in MongoDB, under the Database `peerprepMatchingServiceDB` and `matchingevents` collection.
10
-
4. Open 2 terminals: One to run the service, the other to run the test script.
11
-
5. On either terminal: Open Docker, then run `docker pull redis:latest`, then `docker run --name redis-local -p 6379:6379 -d redis`.
12
-
6. First terminal: Run `npm run dev`. Wait for the messages that the server is running and that it has successfully connected to MongoDB.
13
-
7. Second terminal: Run `node testClientREST` or `node testClientEvent` and watch the tests go. The former uses the API calls, the latter uses exclusively the socket.io communication.
11
+
# Port to run service on
12
+
PORT=3003
13
+
Port of the service.
14
14
15
-
To add test cases, add them at the bottom of the testClient.js file.
15
+
# Redis configuration
16
+
REDIS_HOST=localhost
17
+
REDIS_PORT=6379
18
+
Redis uri configurations. Note: The port matters for all forms of deployment, but
19
+
editing REDIS_HOST here only affects the local deployment. To affect the name of
20
+
the redis uri, edit the docker-compose.yml file instead. This environment variable is
21
+
overriden there.
16
22
17
-
The testClient.js file also allows you to define delay as you wish, so you can use that to test your race condition prevention delay measures, though I also tried to ensure the implementation of matching here avoids race conditions as much as possible.
23
+
# Matching time periods (In milliseconds)
24
+
MATCHING_INTERVAL=1000
25
+
The matching worker checks for matches for matches every ^ milliseconds.
26
+
RELAXATION_INTERVAL=3000
27
+
The matching worker relaxes requirements from users for matching every ^ milliseconds.
28
+
The first time ^ milliseconds passes, the users will be matched with only category considered.
29
+
The second time ^ milliseconds passes, the users will be matched with only difficulty considered.
30
+
At least one of category or difficulty must match.
31
+
MATCH_TIMEOUT=30000
32
+
Users will be considered as having timed out if the ^ milliseconds have passed.
33
+
CLEANUP_INTERVAL=75000
34
+
Stale users will be checked and cleansed every ^ milliseconds by the staleUserCleaner.
0 commit comments