Fix-messaging-calendar-issues (#11424)

- fixing Event Calendar bug due to TypeORM limitations
- avoid systematic crash on contact creation jobs, simply logging
This commit is contained in:
Guillim
2025-04-07 17:13:13 +02:00
committed by GitHub
parent 69da046812
commit 6451b7b5e3
2 changed files with 39 additions and 24 deletions

View File

@ -106,13 +106,18 @@ export class CalendarEventsImportService {
(event) => event.externalId,
);
await this.calendarSaveEventsService.saveCalendarEventsAndEnqueueContactCreationJob(
filteredEvents,
calendarChannel,
connectedAccount,
workspaceId,
);
const BATCH_SIZE = 1000;
for (let i = 0; i < filteredEvents.length; i = i + BATCH_SIZE) {
const eventsBatch = filteredEvents.slice(i, i + BATCH_SIZE);
await this.calendarSaveEventsService.saveCalendarEventsAndEnqueueContactCreationJob(
eventsBatch,
calendarChannel,
connectedAccount,
workspaceId,
);
}
const calendarChannelEventAssociationRepository =
await this.twentyORMManager.getRepository<CalendarChannelEventAssociationWorkspaceEntity>(
'calendarChannelEventAssociation',

View File

@ -6,6 +6,7 @@ import compact from 'lodash.compact';
import { Any, EntityManager, Repository } from 'typeorm';
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
import { ExceptionHandlerService } from 'src/engine/core-modules/exception-handler/exception-handler.service';
import { FieldActorSource } from 'src/engine/metadata-modules/field-metadata/composite-types/actor.composite-type';
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
@ -36,6 +37,7 @@ export class CreateCompanyAndContactService {
@InjectRepository(ObjectMetadataEntity, 'metadata')
private readonly objectMetadataRepository: Repository<ObjectMetadataEntity>,
private readonly twentyORMGlobalManager: TwentyORMGlobalManager,
private readonly exceptionHandlerService: ExceptionHandlerService,
) {}
private async createCompaniesAndPeople(
@ -205,26 +207,34 @@ export class CreateCompanyAndContactService {
}
for (const contactsBatch of contactsBatches) {
const createdPeople = await this.createCompaniesAndPeople(
connectedAccount,
contactsBatch,
workspaceId,
source,
);
try {
const createdPeople = await this.createCompaniesAndPeople(
connectedAccount,
contactsBatch,
workspaceId,
source,
);
this.workspaceEventEmitter.emitDatabaseBatchEvent({
objectMetadataNameSingular: 'person',
action: DatabaseEventAction.CREATED,
events: createdPeople.map((createdPerson) => ({
// Fix ' as string': TypeORM typing issue... id is always returned when using save
recordId: createdPerson.id as string,
objectMetadata,
properties: {
after: createdPerson,
this.workspaceEventEmitter.emitDatabaseBatchEvent({
objectMetadataNameSingular: 'person',
action: DatabaseEventAction.CREATED,
events: createdPeople.map((createdPerson) => ({
// Fix ' as string': TypeORM typing issue... id is always returned when using save
recordId: createdPerson.id as string,
objectMetadata,
properties: {
after: createdPerson,
},
})),
workspaceId,
});
} catch (error) {
this.exceptionHandlerService.captureExceptions([error], {
workspace: {
id: workspaceId,
},
})),
workspaceId,
});
});
}
}
}
}