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:
Charles Bochet
2025-08-04 17:16:16 +02:00
committed by GitHub
parent d958447bb6
commit 2eeddcddc6
14 changed files with 656 additions and 553 deletions
@@ -1 +1 @@
export const MESSAGING_THROTTLE_MAX_ATTEMPTS = 4;
export const MESSAGING_THROTTLE_MAX_ATTEMPTS = 5;
@@ -1 +1 @@
export const MESSAGING_GMAIL_USERS_MESSAGES_GET_BATCH_SIZE = 200;
export const MESSAGING_GMAIL_USERS_MESSAGES_GET_BATCH_SIZE = 400;
@@ -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