feat(messaging): skip webhook-active channels in list-fetch crons until sync is stale (#22183)

<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/twentyhq/twenty/pull/22183?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
This commit is contained in:
neo773
2026-06-25 20:31:17 +05:30
committed by GitHub
parent f270fb25c8
commit 24c042f0ef
5 changed files with 72 additions and 3 deletions
@@ -0,0 +1,33 @@
import { isLastSuccessfulSyncStale } from 'src/modules/connected-account/utils/is-last-successful-sync-stale.util';
import { WEBHOOK_SYNC_STALENESS_THRESHOLD_MS } from 'src/modules/connected-account/webhook-subscription-manager/constants/webhook-sync-staleness-threshold-ms.constant';
jest.useFakeTimers().setSystemTime(new Date('2024-01-01'));
describe('isLastSuccessfulSyncStale', () => {
it('should return true when the last sync is older than the staleness threshold', () => {
const syncedAt = new Date(
Date.now() - WEBHOOK_SYNC_STALENESS_THRESHOLD_MS - 1,
).toISOString();
expect(isLastSuccessfulSyncStale(syncedAt)).toBe(true);
});
it('should return false when the last sync is within the staleness threshold', () => {
const syncedAt = new Date(
Date.now() - WEBHOOK_SYNC_STALENESS_THRESHOLD_MS + 1,
).toISOString();
expect(isLastSuccessfulSyncStale(syncedAt)).toBe(false);
});
it('should return true when the channel has never been synced', () => {
expect(isLastSuccessfulSyncStale(null)).toBe(true);
expect(isLastSuccessfulSyncStale(undefined)).toBe(true);
});
it('should throw an error when the timestamp is invalid', () => {
expect(() => {
isLastSuccessfulSyncStale('invalid-date');
}).toThrow('Invalid date format');
});
});
@@ -0,0 +1,19 @@
import { isDefined } from 'twenty-shared/utils';
import { WEBHOOK_SYNC_STALENESS_THRESHOLD_MS } from 'src/modules/connected-account/webhook-subscription-manager/constants/webhook-sync-staleness-threshold-ms.constant';
export const isLastSuccessfulSyncStale = (
syncedAt?: string | null,
): boolean => {
if (!isDefined(syncedAt)) {
return true;
}
const syncedTime = new Date(syncedAt).getTime();
if (isNaN(syncedTime)) {
throw new Error('Invalid date format');
}
return Date.now() - syncedTime > WEBHOOK_SYNC_STALENESS_THRESHOLD_MS;
};
@@ -0,0 +1 @@
export const WEBHOOK_SYNC_STALENESS_THRESHOLD_MS = 60 * 60 * 1000;