Skip to content

Commit

Permalink
6687 change messaging import cron job to run every minute (#6704)
Browse files Browse the repository at this point in the history
Closes #6687
  • Loading branch information
bosiraphael authored Aug 22, 2024
1 parent 9898ca3 commit 579c2eb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { MessageQueue } from 'src/engine/integrations/message-queue/message-queu
import { MessageQueueService } from 'src/engine/integrations/message-queue/services/message-queue.service';
import { MessagingMessagesImportCronJob } from 'src/modules/messaging/message-import-manager/crons/jobs/messaging-messages-import.cron.job';

const MESSAGING_MESSAGES_IMPORT_CRON_PATTERN = '*/1 * * * *';

@Command({
name: 'cron:messaging:messages-import',
description: 'Starts a cron job to fetch all messages from cache',
Expand All @@ -23,7 +25,7 @@ export class MessagingMessagesImportCronCommand extends CommandRunner {
undefined,
{
repeat: {
every: 30000,
pattern: MESSAGING_MESSAGES_IMPORT_CRON_PATTERN,
},
},
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';

import { Repository } from 'typeorm';
Expand All @@ -24,8 +23,6 @@ import {

@Processor(MessageQueue.cronQueue)
export class MessagingMessagesImportCronJob {
private readonly logger = new Logger(MessagingMessagesImportCronJob.name);

constructor(
@InjectRepository(Workspace, 'core')
private readonly workspaceRepository: Repository<Workspace>,
Expand All @@ -51,23 +48,20 @@ export class MessagingMessagesImportCronJob {
);

const messageChannels = await messageChannelRepository.find({
select: ['id', 'isSyncEnabled', 'syncStage'],
where: {
isSyncEnabled: true,
syncStage: MessageChannelSyncStage.MESSAGES_IMPORT_PENDING,
},
});

for (const messageChannel of messageChannels) {
if (
messageChannel.isSyncEnabled &&
messageChannel.syncStage ===
MessageChannelSyncStage.MESSAGES_IMPORT_PENDING
) {
await this.messageQueueService.add<MessagingMessagesImportJobData>(
MessagingMessagesImportJob.name,
{
workspaceId: activeWorkspace.id,
messageChannelId: messageChannel.id,
},
);
}
await this.messageQueueService.add<MessagingMessagesImportJobData>(
MessagingMessagesImportJob.name,
{
workspaceId: activeWorkspace.id,
messageChannelId: messageChannel.id,
},
);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const MESSAGING_GMAIL_USERS_MESSAGES_GET_BATCH_SIZE = 100;
export const MESSAGING_GMAIL_USERS_MESSAGES_GET_BATCH_SIZE = 200;

0 comments on commit 579c2eb

Please sign in to comment.