Add try catch around messaging monitoring cron and fix decorators (#7207)
Add try catch around messaging monitoring cron and fix decorators:`@Process` and `@SentryCronMonitor` were inverted.
This commit is contained in:
@ -6,7 +6,7 @@ import { MessageQueueService } from 'src/engine/core-modules/message-queue/servi
|
||||
import {
|
||||
MESSAGING_MESSAGE_CHANNEL_SYNC_STATUS_MONITORING_CRON_PATTERN,
|
||||
MessagingMessageChannelSyncStatusMonitoringCronJob,
|
||||
} from 'src/modules/messaging/monitoring/crons/jobs/messaging-message-channel-sync-status-monitoring.cron';
|
||||
} from 'src/modules/messaging/monitoring/crons/jobs/messaging-message-channel-sync-status-monitoring.cron.job';
|
||||
|
||||
@Command({
|
||||
name: 'cron:messaging:monitoring:message-channel-sync-status',
|
||||
|
||||
@ -5,6 +5,7 @@ import snakeCase from 'lodash.snakecase';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import { SentryCronMonitor } from 'src/engine/core-modules/cron/sentry-cron-monitor.decorator';
|
||||
import { ExceptionHandlerService } from 'src/engine/core-modules/exception-handler/exception-handler.service';
|
||||
import { Process } from 'src/engine/core-modules/message-queue/decorators/process.decorator';
|
||||
import { Processor } from 'src/engine/core-modules/message-queue/decorators/processor.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
@ -30,13 +31,14 @@ export class MessagingMessageChannelSyncStatusMonitoringCronJob {
|
||||
private readonly workspaceRepository: Repository<Workspace>,
|
||||
private readonly messagingTelemetryService: MessagingTelemetryService,
|
||||
private readonly twentyORMGlobalManager: TwentyORMGlobalManager,
|
||||
private readonly exceptionHandlerService: ExceptionHandlerService,
|
||||
) {}
|
||||
|
||||
@Process(MessagingMessageChannelSyncStatusMonitoringCronJob.name)
|
||||
@SentryCronMonitor(
|
||||
MessagingMessageChannelSyncStatusMonitoringCronJob.name,
|
||||
MESSAGING_MESSAGE_CHANNEL_SYNC_STATUS_MONITORING_CRON_PATTERN,
|
||||
)
|
||||
@Process(MessagingMessageChannelSyncStatusMonitoringCronJob.name)
|
||||
async handle(): Promise<void> {
|
||||
this.logger.log('Starting message channel sync status monitoring...');
|
||||
|
||||
@ -54,27 +56,35 @@ export class MessagingMessageChannelSyncStatusMonitoringCronJob {
|
||||
});
|
||||
|
||||
for (const activeWorkspace of activeWorkspaces) {
|
||||
const messageChannelRepository =
|
||||
await this.twentyORMGlobalManager.getRepositoryForWorkspace<MessageChannelWorkspaceEntity>(
|
||||
activeWorkspace.id,
|
||||
'messageChannel',
|
||||
);
|
||||
const messageChannels = await messageChannelRepository.find({
|
||||
select: ['id', 'syncStatus', 'connectedAccountId'],
|
||||
});
|
||||
try {
|
||||
const messageChannelRepository =
|
||||
await this.twentyORMGlobalManager.getRepositoryForWorkspace<MessageChannelWorkspaceEntity>(
|
||||
activeWorkspace.id,
|
||||
'messageChannel',
|
||||
);
|
||||
const messageChannels = await messageChannelRepository.find({
|
||||
select: ['id', 'syncStatus', 'connectedAccountId'],
|
||||
});
|
||||
|
||||
for (const messageChannel of messageChannels) {
|
||||
if (!messageChannel.syncStatus) {
|
||||
continue;
|
||||
for (const messageChannel of messageChannels) {
|
||||
if (!messageChannel.syncStatus) {
|
||||
continue;
|
||||
}
|
||||
await this.messagingTelemetryService.track({
|
||||
eventName: `message_channel.monitoring.sync_status.${snakeCase(
|
||||
messageChannel.syncStatus,
|
||||
)}`,
|
||||
workspaceId: activeWorkspace.id,
|
||||
connectedAccountId: messageChannel.connectedAccountId,
|
||||
messageChannelId: messageChannel.id,
|
||||
message: messageChannel.syncStatus,
|
||||
});
|
||||
}
|
||||
await this.messagingTelemetryService.track({
|
||||
eventName: `message_channel.monitoring.sync_status.${snakeCase(
|
||||
messageChannel.syncStatus,
|
||||
)}`,
|
||||
workspaceId: activeWorkspace.id,
|
||||
connectedAccountId: messageChannel.connectedAccountId,
|
||||
messageChannelId: messageChannel.id,
|
||||
message: messageChannel.syncStatus,
|
||||
} catch (error) {
|
||||
this.exceptionHandlerService.captureExceptions([error], {
|
||||
user: {
|
||||
workspaceId: activeWorkspace.id,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -7,7 +7,7 @@ import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { DataSourceEntity } from 'src/engine/metadata-modules/data-source/data-source.entity';
|
||||
import { MessagingCommonModule } from 'src/modules/messaging/common/messaging-common.module';
|
||||
import { MessagingMessageChannelSyncStatusMonitoringCronCommand } from 'src/modules/messaging/monitoring/crons/commands/messaging-message-channel-sync-status-monitoring.cron.command';
|
||||
import { MessagingMessageChannelSyncStatusMonitoringCronJob } from 'src/modules/messaging/monitoring/crons/jobs/messaging-message-channel-sync-status-monitoring.cron';
|
||||
import { MessagingMessageChannelSyncStatusMonitoringCronJob } from 'src/modules/messaging/monitoring/crons/jobs/messaging-message-channel-sync-status-monitoring.cron.job';
|
||||
import { MessagingTelemetryService } from 'src/modules/messaging/monitoring/services/messaging-telemetry.service';
|
||||
|
||||
@Module({
|
||||
|
||||
Reference in New Issue
Block a user