The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Fix fetchAllMessages cronJob when deleted datasource (#4355)
Weikoe7733a1b7a5b
diff --git a/packages/twenty-server/src/workspace/messaging/commands/crons/fetch-all-workspaces-messages.job.ts b/packages/twenty-server/src/workspace/messaging/commands/crons/fetch-all-workspaces-messages.job.tsindex 40709500922..9f5712d3ad1 100644--- a/packages/twenty-server/src/workspace/messaging/commands/crons/fetch-all-workspaces-messages.job.ts+++ b/packages/twenty-server/src/workspace/messaging/commands/crons/fetch-all-workspaces-messages.job.ts@@ -1,4 +1,4 @@-import { Inject, Injectable } from '@nestjs/common';+import { Inject, Injectable, Logger } from '@nestjs/common';import { InjectRepository } from '@nestjs/typeorm';import { Repository } from 'typeorm';@@ -8,16 +8,18 @@ import { MessageQueueJob } from 'src/integrations/message-queue/interfaces/messaimport { MessageQueue } from 'src/integrations/message-queue/message-queue.constants';import { MessageQueueService } from 'src/integrations/message-queue/services/message-queue.service';import { ConnectedAccountService } from 'src/workspace/messaging/repositories/connected-account/connected-account.service';+import { Workspace } from 'src/core/workspace/workspace.entity';import {GmailPartialSyncJobData,GmailPartialSyncJob,} from 'src/workspace/messaging/jobs/gmail-partial-sync.job';-import { Workspace } from 'src/core/workspace/workspace.entity';@Injectable()export class FetchAllWorkspacesMessagesJobimplements MessageQueueJob<undefined>{+ private readonly logger = new Logger(FetchAllWorkspacesMessagesJob.name);+constructor(@InjectRepository(Workspace, 'core')private readonly workspaceRepository: Repository<Workspace>,@@ -42,20 +44,29 @@ export class FetchAllWorkspacesMessagesJob}private async fetchWorkspaceMessages(workspaceId: string): Promise<void> {- const connectedAccounts =- await this.connectedAccountService.getAll(workspaceId);-- for (const connectedAccount of connectedAccounts) {- await this.messageQueueService.add<GmailPartialSyncJobData>(- GmailPartialSyncJob.name,- {- workspaceId,- connectedAccountId: connectedAccount.id,- },- {- retryLimit: 2,- },+ try {+ const connectedAccounts =+ await this.connectedAccountService.getAll(workspaceId);++ for (const connectedAccount of connectedAccounts) {+ await this.messageQueueService.add<GmailPartialSyncJobData>(+ GmailPartialSyncJob.name,+ {+ workspaceId,+ connectedAccountId: connectedAccount.id,+ },+ {+ retryLimit: 2,+ },+ );+ }+ } catch (error) {+ this.logger.error(+ `Error while fetching workspace messages for workspace ${workspaceId}`,);+ this.logger.error(error);++ return;}}}