Skip to content

Commit

Permalink
chore: log rabbitmq errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nicotsx committed Dec 8, 2024
1 parent 53adfe8 commit 355b679
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"nestjs-spelunker": "^1.3.1",
"nestjs-zod": "^4.2.0",
"node-cron": "^3.0.3",
"pg": "^8.13.1",
"rabbitmq-client": "^5.0.1",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1",
Expand Down Expand Up @@ -105,7 +106,6 @@
"vite-tsconfig-paths": "5.1.4",
"vitest": "^2.1.8",
"vitest-mock-extended": "^2.0.2",
"wait-for-expect": "^3.0.2",
"pg": "^8.13.1"
"wait-for-expect": "^3.0.2"
}
}
9 changes: 8 additions & 1 deletion packages/backend/src/modules/queue/queue.factory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { LoggerService } from '@/core/logger/logger.service';
import { Injectable } from '@nestjs/common';
import Sentry from '@sentry/nestjs';
import { Connection } from 'rabbitmq-client';
import { type ZodSchema, z } from 'zod';
import { Queue } from './queue.entity';
Expand All @@ -7,12 +9,17 @@ import { Queue } from './queue.entity';
export class QueueFactory {
private rabbit: Connection;

public constructor() {
public constructor(private readonly logger: LoggerService) {
this.initializeConnection();
}

private initializeConnection() {
this.rabbit = new Connection({ url: 'amqp://guest:guest@localhost:5672' });

this.rabbit.on('error', (error) => {
this.logger.error('RabbitMQ connection error:', error);
Sentry.captureException(error);
});
}

public createQueue<T extends ZodSchema, R extends ZodSchema>(params: {
Expand Down
4 changes: 3 additions & 1 deletion packages/backend/src/tests/integration/app-lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ConfigurationService } from '@/core/config/configuration.service';
import { DatabaseService } from '@/core/database/database.service';
import { appStore } from '@/core/database/drizzle/schema';
import { FilesystemService } from '@/core/filesystem/filesystem.service';
import type { LoggerService } from '@/core/logger/logger.service';
import { AppLifecycleCommandFactory } from '@/modules/app-lifecycle/app-lifecycle-command.factory';
import { AppLifecycleService } from '@/modules/app-lifecycle/app-lifecycle.service';
import { AppStoreRepository } from '@/modules/app-stores/app-store.repository';
Expand Down Expand Up @@ -34,7 +35,8 @@ describe('App lifecycle', () => {
let appsRepository: AppsRepository;
let configurationService = mock<ConfigurationService>();
let databaseService = mock<DatabaseService>();
const queueFactory = new QueueFactory();
const loggerService = mock<LoggerService>();
const queueFactory = new QueueFactory(loggerService);
const appEventsQueue = queueFactory.createQueue({
queueName: 'app-events-queue',
workers: 1,
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

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

0 comments on commit 355b679

Please sign in to comment.