Refactor sync sub status and throttle (#5734)
- Rename syncSubStatus to syncStage - Rename ongoingSyncStartedAt to syncStageStartedAt - Remove throttlePauseUntil from db and compute it with syncStageStartedAt and throttleFailureCount
This commit is contained in:
@ -77,7 +77,12 @@ export class MessagingGmailFullMessageListFetchService {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.messageChannelRepository.resetThrottlePauseUntilAndThrottleFailureCount(
|
||||
await this.messageChannelRepository.resetThrottleFailureCount(
|
||||
messageChannel.id,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
await this.messageChannelRepository.resetSyncStageStartedAt(
|
||||
messageChannel.id,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
@ -12,7 +12,7 @@ import { BlocklistRepository } from 'src/modules/connected-account/repositories/
|
||||
import { MessagingTelemetryService } from 'src/modules/messaging/common/services/messaging-telemetry.service';
|
||||
import {
|
||||
MessageChannelWorkspaceEntity,
|
||||
MessageChannelSyncSubStatus,
|
||||
MessageChannelSyncStage,
|
||||
} from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
|
||||
import { createQueriesFromMessageIds } from 'src/modules/messaging/message-import-manager/utils/create-queries-from-message-ids.util';
|
||||
import { filterEmails } from 'src/modules/messaging/message-import-manager/utils/filter-emails.util';
|
||||
@ -50,8 +50,8 @@ export class MessagingGmailMessagesImportService {
|
||||
workspaceId: string,
|
||||
) {
|
||||
if (
|
||||
messageChannel.syncSubStatus !==
|
||||
MessageChannelSyncSubStatus.MESSAGES_IMPORT_PENDING
|
||||
messageChannel.syncStage !==
|
||||
MessageChannelSyncStage.MESSAGES_IMPORT_PENDING
|
||||
) {
|
||||
return;
|
||||
}
|
||||
@ -137,7 +137,12 @@ export class MessagingGmailMessagesImportService {
|
||||
);
|
||||
}
|
||||
|
||||
await this.messageChannelRepository.resetThrottlePauseUntilAndThrottleFailureCount(
|
||||
await this.messageChannelRepository.resetThrottleFailureCount(
|
||||
messageChannel.id,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
await this.messageChannelRepository.resetSyncStageStartedAt(
|
||||
messageChannel.id,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
@ -74,7 +74,12 @@ export class MessagingGmailPartialMessageListFetchService {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.messageChannelRepository.resetThrottlePauseUntilAndThrottleFailureCount(
|
||||
await this.messageChannelRepository.resetThrottleFailureCount(
|
||||
messageChannel.id,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
await this.messageChannelRepository.resetSyncStageStartedAt(
|
||||
messageChannel.id,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
@ -0,0 +1,25 @@
|
||||
import { MESSAGING_THROTTLE_DURATION } from 'src/modules/messaging/common/constants/messaging-throttle-duration';
|
||||
|
||||
export const isThrottled = (
|
||||
syncStageStartedAt: string | null,
|
||||
throttleFailureCount: number,
|
||||
): boolean => {
|
||||
if (!syncStageStartedAt) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (
|
||||
computeThrottlePauseUntil(syncStageStartedAt, throttleFailureCount) >
|
||||
new Date()
|
||||
);
|
||||
};
|
||||
|
||||
const computeThrottlePauseUntil = (
|
||||
syncStageStartedAt: string,
|
||||
throttleFailureCount: number,
|
||||
): Date => {
|
||||
return new Date(
|
||||
new Date(syncStageStartedAt).getTime() +
|
||||
MESSAGING_THROTTLE_DURATION * Math.pow(2, throttleFailureCount - 1),
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user