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:
@ -106,13 +106,18 @@ export class CalendarEventsImportService {
|
|||||||
(event) => event.externalId,
|
(event) => event.externalId,
|
||||||
);
|
);
|
||||||
|
|
||||||
await this.calendarSaveEventsService.saveCalendarEventsAndEnqueueContactCreationJob(
|
const BATCH_SIZE = 1000;
|
||||||
filteredEvents,
|
|
||||||
calendarChannel,
|
|
||||||
connectedAccount,
|
|
||||||
workspaceId,
|
|
||||||
);
|
|
||||||
|
|
||||||
|
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 =
|
const calendarChannelEventAssociationRepository =
|
||||||
await this.twentyORMManager.getRepository<CalendarChannelEventAssociationWorkspaceEntity>(
|
await this.twentyORMManager.getRepository<CalendarChannelEventAssociationWorkspaceEntity>(
|
||||||
'calendarChannelEventAssociation',
|
'calendarChannelEventAssociation',
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import compact from 'lodash.compact';
|
|||||||
import { Any, EntityManager, Repository } from 'typeorm';
|
import { Any, EntityManager, Repository } from 'typeorm';
|
||||||
|
|
||||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
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 { 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 { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||||
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
|
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
|
||||||
@ -36,6 +37,7 @@ export class CreateCompanyAndContactService {
|
|||||||
@InjectRepository(ObjectMetadataEntity, 'metadata')
|
@InjectRepository(ObjectMetadataEntity, 'metadata')
|
||||||
private readonly objectMetadataRepository: Repository<ObjectMetadataEntity>,
|
private readonly objectMetadataRepository: Repository<ObjectMetadataEntity>,
|
||||||
private readonly twentyORMGlobalManager: TwentyORMGlobalManager,
|
private readonly twentyORMGlobalManager: TwentyORMGlobalManager,
|
||||||
|
private readonly exceptionHandlerService: ExceptionHandlerService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
private async createCompaniesAndPeople(
|
private async createCompaniesAndPeople(
|
||||||
@ -205,26 +207,34 @@ export class CreateCompanyAndContactService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const contactsBatch of contactsBatches) {
|
for (const contactsBatch of contactsBatches) {
|
||||||
const createdPeople = await this.createCompaniesAndPeople(
|
try {
|
||||||
connectedAccount,
|
const createdPeople = await this.createCompaniesAndPeople(
|
||||||
contactsBatch,
|
connectedAccount,
|
||||||
workspaceId,
|
contactsBatch,
|
||||||
source,
|
workspaceId,
|
||||||
);
|
source,
|
||||||
|
);
|
||||||
|
|
||||||
this.workspaceEventEmitter.emitDatabaseBatchEvent({
|
this.workspaceEventEmitter.emitDatabaseBatchEvent({
|
||||||
objectMetadataNameSingular: 'person',
|
objectMetadataNameSingular: 'person',
|
||||||
action: DatabaseEventAction.CREATED,
|
action: DatabaseEventAction.CREATED,
|
||||||
events: createdPeople.map((createdPerson) => ({
|
events: createdPeople.map((createdPerson) => ({
|
||||||
// Fix ' as string': TypeORM typing issue... id is always returned when using save
|
// Fix ' as string': TypeORM typing issue... id is always returned when using save
|
||||||
recordId: createdPerson.id as string,
|
recordId: createdPerson.id as string,
|
||||||
objectMetadata,
|
objectMetadata,
|
||||||
properties: {
|
properties: {
|
||||||
after: createdPerson,
|
after: createdPerson,
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
workspaceId,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
this.exceptionHandlerService.captureExceptions([error], {
|
||||||
|
workspace: {
|
||||||
|
id: workspaceId,
|
||||||
},
|
},
|
||||||
})),
|
});
|
||||||
workspaceId,
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user