Add TwentyORM query read timeout exception (#13603)
In this PR: - adding a try / catch around all ORM internal methods save, insert, upsert, findOne, ... - leveraging this error to prevent messageChannels to get FAILED - optimizing messaging BATCH_SIZE and THROTTLE threshold according to local tests - <img width="1510" height="851" alt="image" src="https://github.com/user-attachments/assets/802fd933-caac-4291-9cde-34a1ddf59c06" />
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
||||
export const CALENDAR_THROTTLE_MAX_ATTEMPTS = 4;
|
||||
export const CALENDAR_THROTTLE_MAX_ATTEMPTS = 5;
|
||||
|
||||
+7
-2
@@ -1,6 +1,10 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
|
||||
import { ExceptionHandlerService } from 'src/engine/core-modules/exception-handler/exception-handler.service';
|
||||
import {
|
||||
TwentyORMException,
|
||||
TwentyORMExceptionCode,
|
||||
} from 'src/engine/twenty-orm/exceptions/twenty-orm.exception';
|
||||
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
import { CALENDAR_THROTTLE_MAX_ATTEMPTS } from 'src/modules/calendar/calendar-event-import-manager/constants/calendar-throttle-max-attempts';
|
||||
import {
|
||||
@@ -31,7 +35,7 @@ export class CalendarEventImportErrorHandlerService {
|
||||
) {}
|
||||
|
||||
public async handleDriverException(
|
||||
exception: CalendarEventImportDriverException,
|
||||
exception: CalendarEventImportDriverException | TwentyORMException,
|
||||
syncStep: CalendarEventImportSyncStep,
|
||||
calendarChannel: Pick<
|
||||
CalendarChannelWorkspaceEntity,
|
||||
@@ -47,6 +51,7 @@ export class CalendarEventImportErrorHandlerService {
|
||||
workspaceId,
|
||||
);
|
||||
break;
|
||||
case TwentyORMExceptionCode.QUERY_READ_TIMEOUT:
|
||||
case CalendarEventImportDriverExceptionCode.TEMPORARY_ERROR:
|
||||
await this.handleTemporaryException(
|
||||
syncStep,
|
||||
@@ -158,7 +163,7 @@ export class CalendarEventImportErrorHandlerService {
|
||||
}
|
||||
|
||||
private async handleUnknownException(
|
||||
exception: CalendarEventImportDriverException,
|
||||
exception: { message: string },
|
||||
calendarChannel: Pick<CalendarChannelWorkspaceEntity, 'id'>,
|
||||
workspaceId: string,
|
||||
): Promise<void> {
|
||||
|
||||
+4
-1
@@ -118,7 +118,10 @@ export class ConnectedAccountRefreshTokensService {
|
||||
);
|
||||
}
|
||||
|
||||
this.logger.log(error);
|
||||
this.logger.log(
|
||||
`Error while refreshing tokens on connected account ${connectedAccount.id.slice(0, 7)} in workspace ${workspaceId.slice(0, 7)}`,
|
||||
error,
|
||||
);
|
||||
throw new ConnectedAccountRefreshAccessTokenException(
|
||||
`Error refreshing tokens for connected account ${connectedAccount.id.slice(0, 7)} in workspace ${workspaceId.slice(0, 7)}: ${error.message} ${error?.response?.data?.error_description}`,
|
||||
ConnectedAccountRefreshAccessTokenExceptionCode.REFRESH_ACCESS_TOKEN_FAILED,
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
export const MESSAGING_THROTTLE_MAX_ATTEMPTS = 4;
|
||||
export const MESSAGING_THROTTLE_MAX_ATTEMPTS = 5;
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
export const MESSAGING_GMAIL_USERS_MESSAGES_GET_BATCH_SIZE = 200;
|
||||
export const MESSAGING_GMAIL_USERS_MESSAGES_GET_BATCH_SIZE = 400;
|
||||
|
||||
+7
-2
@@ -3,6 +3,10 @@ import { Injectable } from '@nestjs/common';
|
||||
import { isDefined } from 'class-validator';
|
||||
|
||||
import { ExceptionHandlerService } from 'src/engine/core-modules/exception-handler/exception-handler.service';
|
||||
import {
|
||||
TwentyORMException,
|
||||
TwentyORMExceptionCode,
|
||||
} from 'src/engine/twenty-orm/exceptions/twenty-orm.exception';
|
||||
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
import { MessageChannelSyncStatusService } from 'src/modules/messaging/common/services/message-channel-sync-status.service';
|
||||
import {
|
||||
@@ -36,7 +40,7 @@ export class MessageImportExceptionHandlerService {
|
||||
) {}
|
||||
|
||||
public async handleDriverException(
|
||||
exception: MessageImportDriverException | Error,
|
||||
exception: MessageImportDriverException | Error | TwentyORMException,
|
||||
syncStep: MessageImportSyncStep,
|
||||
messageChannel: Pick<
|
||||
MessageChannelWorkspaceEntity,
|
||||
@@ -53,6 +57,7 @@ export class MessageImportExceptionHandlerService {
|
||||
workspaceId,
|
||||
);
|
||||
break;
|
||||
case TwentyORMExceptionCode.QUERY_READ_TIMEOUT:
|
||||
case MessageImportDriverExceptionCode.TEMPORARY_ERROR:
|
||||
case MessageNetworkExceptionCode.ECONNABORTED:
|
||||
case MessageNetworkExceptionCode.ENOTFOUND:
|
||||
@@ -102,7 +107,7 @@ export class MessageImportExceptionHandlerService {
|
||||
'id' | 'throttleFailureCount'
|
||||
>,
|
||||
workspaceId: string,
|
||||
exception: MessageImportDriverException,
|
||||
exception: { message: string },
|
||||
): Promise<void> {
|
||||
if (
|
||||
messageChannel.throttleFailureCount >= MESSAGING_THROTTLE_MAX_ATTEMPTS
|
||||
|
||||
Reference in New Issue
Block a user