Skip to content

Commit

Permalink
Merge pull request CS3219-AY2324S1#222 from cadencjk/dev
Browse files Browse the repository at this point in the history
Assignment 5 Update
  • Loading branch information
cadencjk authored Nov 5, 2023
2 parents d824bee + 607ed39 commit 52ef9a7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 8 additions & 5 deletions Match/src/services/consumerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const handleExitRequest = (request, channel, queueName, message) => {
if (waitingHost !== undefined) {
const waitingHostRequest = JSON.parse(waitingHost.content.toString());
if (waitingHostRequest.sessionID === request.sessionID) {
logger.log(`Host ${waitingHostRequest.id} exited the ${queueName} queue`);
logger.debug(`Host ${waitingHostRequest.id} has exited ${queueName} queue`);

const response = { message: `You have exited the queue` };
channel.sendToQueue(waitingHostRequest.replyTo, bufferData(response), {
Expand All @@ -48,7 +48,7 @@ const handleExitRequest = (request, channel, queueName, message) => {

// Handle request when the host in current queue times out
const handleTimeoutRequest = (request, channel, message) => {
logger.log(`Host ${request.id} timed out`);
logger.debug(`Host ${request.id} timed out`);

const response = { message: `No match found. You have timed out!` };
channel.sendToQueue(request.replyTo, bufferData(response), {
Expand All @@ -65,7 +65,7 @@ const checkMultipleTabsRequest = (request, channel, queueName) => {
const waitingHostResponse = {
message: `You are waiting in multiple tabs!`,
};
logger.log(`Host ${waitingHostRequest.id} is waiting in multiple tabs`);
logger.debug(`Host ${waitingHostRequest.id} is waiting in multiple tabs, removing earlier session from queue`);

// Send the response to waiting host
channel.sendToQueue(
Expand All @@ -83,7 +83,7 @@ const checkMultipleTabsRequest = (request, channel, queueName) => {
// Handle request when 2 unique users are matched
const handleMatchedRequest = (request, channel, queueName, message, waitingHost) => {
const waitingHostRequest = JSON.parse(waitingHost.content.toString());
logger.log(`Matched Host ${waitingHostRequest.id} with Host ${request.id}`);
logger.logSuccess(`Matched Host ${waitingHostRequest.id} with Host ${request.id}`);

const roomId = generateUniqueRoomId();
const response = {
Expand All @@ -92,6 +92,9 @@ const handleMatchedRequest = (request, channel, queueName, message, waitingHost)
roomId: roomId,
};

logger.debug(`Removed host ${waitingHostRequest.id} from ${queueName} queue`);
logger.debug(`Removed host ${request.id} from ${queueName} queue`);

// Send the match response to the waiting host
channel.sendToQueue(waitingHostRequest.replyTo, bufferData(response), {
correlationId: waitingHostRequest.correlationId,
Expand Down Expand Up @@ -122,7 +125,7 @@ const handleNoMatchRequest = (request, channel, queueName, message) => {

// Ensure that there is no match before sending the timeout response
if (waitingHostRequest.correlationId === request.correlationId) {
logger.log(`Host ${waitingHostRequest.id} timed out`);
logger.debug(`Host ${waitingHostRequest.id} timed out`);

const response = { message: `No match found. You have timed out!` };
channel.sendToQueue(request.replyTo, bufferData(response), {
Expand Down
4 changes: 1 addition & 3 deletions Match/src/services/producerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const joinQueue = async (jwt, queueName, sessionID) => {
sessionID: sessionID,
};

logger.logSuccess(`Host ${userId} joined ${queueName} queue successfully`);
logger.debug(`Host ${userId} joined ${queueName} queue successfully`);

// Send the message to the request queue with the queue name as a property
channel.sendToQueue(requestQueue, Buffer.from(JSON.stringify(message)), {
Expand Down Expand Up @@ -104,8 +104,6 @@ const exitQueue = async (jwt, queueName, sessionID) => {
sessionID: sessionID,
};

logger.logSuccess(`Host ${userId} leaved ${queueName} queue successfully`);

// Send the message to the request queue
channel.sendToQueue(requestQueue, Buffer.from(JSON.stringify(message)));
};
Expand Down

0 comments on commit 52ef9a7

Please sign in to comment.