mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-26 13:31:45 +03:00
Fix fetchAllMessages cronJob when deleted datasource (#4355)
This commit is contained in:
parent
e8252eca86
commit
e7733a1b7a
@ -1,4 +1,4 @@
|
|||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Inject, Injectable, Logger } from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
@ -8,16 +8,18 @@ import { MessageQueueJob } from 'src/integrations/message-queue/interfaces/messa
|
|||||||
import { MessageQueue } from 'src/integrations/message-queue/message-queue.constants';
|
import { MessageQueue } from 'src/integrations/message-queue/message-queue.constants';
|
||||||
import { MessageQueueService } from 'src/integrations/message-queue/services/message-queue.service';
|
import { MessageQueueService } from 'src/integrations/message-queue/services/message-queue.service';
|
||||||
import { ConnectedAccountService } from 'src/workspace/messaging/repositories/connected-account/connected-account.service';
|
import { ConnectedAccountService } from 'src/workspace/messaging/repositories/connected-account/connected-account.service';
|
||||||
|
import { Workspace } from 'src/core/workspace/workspace.entity';
|
||||||
import {
|
import {
|
||||||
GmailPartialSyncJobData,
|
GmailPartialSyncJobData,
|
||||||
GmailPartialSyncJob,
|
GmailPartialSyncJob,
|
||||||
} from 'src/workspace/messaging/jobs/gmail-partial-sync.job';
|
} from 'src/workspace/messaging/jobs/gmail-partial-sync.job';
|
||||||
import { Workspace } from 'src/core/workspace/workspace.entity';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class FetchAllWorkspacesMessagesJob
|
export class FetchAllWorkspacesMessagesJob
|
||||||
implements MessageQueueJob<undefined>
|
implements MessageQueueJob<undefined>
|
||||||
{
|
{
|
||||||
|
private readonly logger = new Logger(FetchAllWorkspacesMessagesJob.name);
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(Workspace, 'core')
|
@InjectRepository(Workspace, 'core')
|
||||||
private readonly workspaceRepository: Repository<Workspace>,
|
private readonly workspaceRepository: Repository<Workspace>,
|
||||||
@ -42,20 +44,29 @@ export class FetchAllWorkspacesMessagesJob
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async fetchWorkspaceMessages(workspaceId: string): Promise<void> {
|
private async fetchWorkspaceMessages(workspaceId: string): Promise<void> {
|
||||||
const connectedAccounts =
|
try {
|
||||||
await this.connectedAccountService.getAll(workspaceId);
|
const connectedAccounts =
|
||||||
|
await this.connectedAccountService.getAll(workspaceId);
|
||||||
|
|
||||||
for (const connectedAccount of connectedAccounts) {
|
for (const connectedAccount of connectedAccounts) {
|
||||||
await this.messageQueueService.add<GmailPartialSyncJobData>(
|
await this.messageQueueService.add<GmailPartialSyncJobData>(
|
||||||
GmailPartialSyncJob.name,
|
GmailPartialSyncJob.name,
|
||||||
{
|
{
|
||||||
workspaceId,
|
workspaceId,
|
||||||
connectedAccountId: connectedAccount.id,
|
connectedAccountId: connectedAccount.id,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
retryLimit: 2,
|
retryLimit: 2,
|
||||||
},
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(
|
||||||
|
`Error while fetching workspace messages for workspace ${workspaceId}`,
|
||||||
);
|
);
|
||||||
|
this.logger.error(error);
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user