From ce6bcc7e7243b8f5266c6c43d13356759e281da1 Mon Sep 17 00:00:00 2001 From: Aubin Date: Thu, 6 Mar 2025 17:22:13 +0100 Subject: [PATCH] keep lastSyncTimestamp and retentionPeriodDays separate --- .../connectors/gong/temporal/activities.ts | 2 +- connectors/src/resources/gong_resources.ts | 34 +++++++++++++------ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/connectors/src/connectors/gong/temporal/activities.ts b/connectors/src/connectors/gong/temporal/activities.ts index efefcc81a81d..9862fd150692 100644 --- a/connectors/src/connectors/gong/temporal/activities.ts +++ b/connectors/src/connectors/gong/temporal/activities.ts @@ -99,7 +99,7 @@ export async function gongSyncTranscriptsActivity({ let pageCursor = null; do { const { transcripts, nextPageCursor } = await gongClient.getTranscripts({ - startTimestamp: configuration.lastSyncTimestamp, + startTimestamp: configuration.getSyncStartTimestamp(), pageCursor, }); const callsMetadata = await getTranscriptsMetadata({ diff --git a/connectors/src/resources/gong_resources.ts b/connectors/src/resources/gong_resources.ts index aa6914fa0669..24c6dc3caffc 100644 --- a/connectors/src/resources/gong_resources.ts +++ b/connectors/src/resources/gong_resources.ts @@ -87,23 +87,37 @@ export class GongConfigurationResource extends BaseResource { await this.update({ - lastSyncTimestamp: this.retentionPeriodDays - ? Date.now() - this.retentionPeriodDays * 24 * 60 * 60 * 1000 - : null, + lastSyncTimestamp: null, }); } async setLastSyncTimestamp(timestamp: number): Promise { await this.update({ - // Can't set a timestamp older than what is enforced by the retention period. - lastSyncTimestamp: this.retentionPeriodDays - ? Math.max( - timestamp, - Date.now() - this.retentionPeriodDays * 24 * 60 * 60 * 1000 - ) - : timestamp, + lastSyncTimestamp: timestamp, }); } + + async setRetentionPeriodDays( + retentionPeriodDays: number | null + ): Promise { + await this.update({ + retentionPeriodDays, + }); + } + + // Returns the timestamp to start syncing from. + getSyncStartTimestamp() { + if (!this.retentionPeriodDays) { + return this.lastSyncTimestamp; + } + if (!this.lastSyncTimestamp) { + return Date.now() - this.retentionPeriodDays * 24 * 60 * 60 * 1000; + } + return Math.max( + this.lastSyncTimestamp, + Date.now() - this.retentionPeriodDays * 24 * 60 * 60 * 1000 + ); + } } export type GongUserBlob = Omit<