[Messaging] Gmail Full sync pagination (#3664)
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Inject } from '@nestjs/common';
|
||||
|
||||
import { Command, CommandRunner, Option } from 'nest-commander';
|
||||
import { Repository } from 'typeorm';
|
||||
@ -7,8 +8,13 @@ import {
|
||||
FeatureFlagEntity,
|
||||
FeatureFlagKeys,
|
||||
} from 'src/core/feature-flag/feature-flag.entity';
|
||||
import { MessagingProducer } from 'src/workspace/messaging/producers/messaging-producer';
|
||||
import { MessagingUtilsService } from 'src/workspace/messaging/services/messaging-utils.service';
|
||||
import { MessageQueue } from 'src/integrations/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/integrations/message-queue/services/message-queue.service';
|
||||
import {
|
||||
GmailPartialSyncJob,
|
||||
GmailPartialSyncJobData,
|
||||
} from 'src/workspace/messaging/jobs/gmail-partial-sync.job';
|
||||
|
||||
interface GmailPartialSyncOptions {
|
||||
workspaceId: string;
|
||||
@ -20,11 +26,11 @@ interface GmailPartialSyncOptions {
|
||||
})
|
||||
export class GmailPartialSyncCommand extends CommandRunner {
|
||||
constructor(
|
||||
private readonly messagingProducer: MessagingProducer,
|
||||
private readonly utils: MessagingUtilsService,
|
||||
|
||||
@InjectRepository(FeatureFlagEntity, 'core')
|
||||
private readonly featureFlagRepository: Repository<FeatureFlagEntity>,
|
||||
@Inject(MessageQueue.messagingQueue)
|
||||
private readonly messageQueueService: MessageQueueService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
@ -58,13 +64,25 @@ export class GmailPartialSyncCommand extends CommandRunner {
|
||||
}
|
||||
|
||||
private async fetchWorkspaceMessages(workspaceId: string): Promise<void> {
|
||||
const connectedAccounts =
|
||||
await this.utils.getConnectedAccountsFromWorkspaceId(workspaceId);
|
||||
const { workspaceDataSource, dataSourceMetadata } =
|
||||
await this.utils.getDataSourceMetadataWorkspaceMetadata(workspaceId);
|
||||
|
||||
const connectedAccounts = await this.utils.getConnectedAccounts(
|
||||
dataSourceMetadata,
|
||||
workspaceDataSource,
|
||||
);
|
||||
|
||||
for (const connectedAccount of connectedAccounts) {
|
||||
await this.messagingProducer.enqueueGmailPartialSync(
|
||||
{ workspaceId, connectedAccountId: connectedAccount.id },
|
||||
`${workspaceId}-${connectedAccount.id}`,
|
||||
await this.messageQueueService.add<GmailPartialSyncJobData>(
|
||||
GmailPartialSyncJob.name,
|
||||
{
|
||||
workspaceId,
|
||||
connectedAccountId: connectedAccount.id,
|
||||
},
|
||||
{
|
||||
id: `${workspaceId}-${connectedAccount.id}`,
|
||||
retryLimit: 2,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user