Skip to content

Commit

Permalink
fix: track job errors in Sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
magrinj committed Jun 11, 2024
1 parent 51a13b9 commit c09d3a4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
4 changes: 4 additions & 0 deletions packages/twenty-server/src/database/typeorm/typeorm.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm';

import { typeORMCoreModuleOptions } from 'src/database/typeorm/core/core.datasource';
import { EnvironmentModule } from 'src/engine/integrations/environment/environment.module';
import { TwentyORMModule } from 'src/engine/twenty-orm/twenty-orm.module';

import { TypeORMService } from './typeorm.service';

Expand All @@ -28,6 +29,9 @@ const coreTypeORMFactory = async (): Promise<TypeOrmModuleOptions> => ({
useFactory: coreTypeORMFactory,
name: 'core',
}),
TwentyORMModule.register({
workspaceEntities: ['dist/src/**/*.workspace-entity{.ts,.js}'],
}),
EnvironmentModule,
],
providers: [TypeORMService],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { TimelineMessagingModule } from 'src/engine/core-modules/messaging/timel
import { TimelineCalendarEventModule } from 'src/engine/core-modules/calendar/timeline-calendar-event.module';
import { BillingModule } from 'src/engine/core-modules/billing/billing.module';
import { HealthModule } from 'src/engine/core-modules/health/health.module';
import { TwentyORMModule } from 'src/engine/twenty-orm/twenty-orm.module';
import { PostgresCredentialsModule } from 'src/engine/core-modules/postgres-credentials/postgres-credentials.module';

import { AnalyticsModule } from './analytics/analytics.module';
Expand All @@ -19,9 +18,6 @@ import { ClientConfigModule } from './client-config/client-config.module';

@Module({
imports: [
TwentyORMModule.register({
workspaceEntities: ['dist/src/**/*.workspace-entity{.ts,.js}'],
}),
HealthModule,
AnalyticsModule,
AuthModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { MessageQueueWorkerOptions } from 'src/engine/integrations/message-queue

import { MessageQueueService } from 'src/engine/integrations/message-queue/services/message-queue.service';
import { getQueueToken } from 'src/engine/integrations/message-queue/utils/get-queue-token.util';
import { ExceptionHandlerService } from 'src/engine/integrations/exception-handler/exception-handler.service';
import { shouldFilterException } from 'src/engine/utils/global-exception-handler.util';

import { MessageQueueMetadataAccessor } from './message-queue-metadata.accessor';

Expand All @@ -25,6 +27,7 @@ export class MessageQueueExplorer implements OnModuleInit {
private readonly discoveryService: DiscoveryService,
private readonly metadataAccessor: MessageQueueMetadataAccessor,
private readonly metadataScanner: MetadataScanner,
private readonly exceptionHandlerService: ExceptionHandlerService,
) {}

onModuleInit() {
Expand Down Expand Up @@ -147,15 +150,29 @@ export class MessageQueueExplorer implements OnModuleInit {

for (const [methodName, metadata] of processMetadataCollection) {
if (job.name === metadata?.jobName || !metadata?.jobName) {
await contextInstance[methodName].call(contextInstance, job);
try {
await contextInstance[methodName].call(contextInstance, job);
} catch (err) {
if (!shouldFilterException(err)) {
this.exceptionHandlerService.captureExceptions([err]);
}
throw err;
}
}
}
}, options);
} else {
queue.work(async (job) => {
for (const [methodName, metadata] of processMetadataCollection) {
if (job.name === metadata?.jobName || !metadata?.jobName) {
await instance[methodName].call(instance, job);
try {
await instance[methodName].call(instance, job);
} catch (err) {
if (!shouldFilterException(err)) {
this.exceptionHandlerService.captureExceptions([err]);
}
throw err;
}
}
}
}, options);
Expand Down

0 comments on commit c09d3a4

Please sign in to comment.