Skip to content

Commit

Permalink
fix: correct controller notify
Browse files Browse the repository at this point in the history
  • Loading branch information
m-paice committed Aug 28, 2024
1 parent 1750468 commit 14084fe
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 22 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vtru-studio-websocket",
"version": "1.1.39",
"version": "1.1.40",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
26 changes: 10 additions & 16 deletions src/controllers/notify/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import debug from 'debug';
import { nanoid } from 'nanoid';

import { RABBITMQ_EXCHANGE_CREATORS } from '../../constants';
import { disconnect, getChannel } from '../../services/rabbitmq';
import { captureException } from '../../services/sentry';
import { io } from '../../services';
import { NotifyEnvelope } from './types';
import { getChannel, disconnect, io } from '../../services';

const logger = debug('controllers:notify');

const uniqueId = nanoid();

// TODO: create dead letter for queue
export const start = async () => {
const channel = await getChannel();

Expand All @@ -35,15 +34,12 @@ export const start = async () => {
});
channel.assertQueue(logQueue, { durable: false });
channel.bindQueue(logQueue, RABBITMQ_EXCHANGE_CREATORS, 'userNotification');
channel.consume(logQueue, async (message) => {
if (!message) return;

channel.consume(logQueue, async (data) => {
if (!data) return;
try {
const parsedMessage = JSON.parse(
message.content.toString().trim()
) as NotifyEnvelope;
const parsedMessage = JSON.parse(data.content.toString().trim());

console.log(parsedMessage);
logger('Received message:', parsedMessage);

const sockets = await io.sockets.in('creators').fetchSockets();

Expand All @@ -56,12 +52,10 @@ export const start = async () => {
}
});

channel.ack(message);
return;
} catch (parsingError) {
captureException(parsingError);
channel.ack(data);
} catch (error) {
logger('Error occurred in controller notify:', error);
}
channel.nack(message);
});

process.once('SIGINT', async () => {
Expand Down
4 changes: 1 addition & 3 deletions src/controllers/notify/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export interface NotifyEnvelope {
export interface NotifyEnvelope extends Record<string, unknown> {
creatorId: string;
fileName: string;
messageType: string;
}

0 comments on commit 14084fe

Please sign in to comment.