fix message channels stuck in ONGOING (#17492)

`markAsMessagesListFetchOngoing()` was missing `syncStageStartedAt`
causing stuck channels to be never recovered.

Regression was caused by commit
[68a9ef57f0](https://github.com/twentyhq/twenty/commit/68a9ef57f0)
This commit is contained in:
neo773
2026-01-28 01:53:29 +05:30
committed by GitHub
parent 51c1fa0137
commit 8fb8b5d2f1
7 changed files with 32 additions and 11 deletions
@@ -54,10 +54,7 @@ export class CalendarOngoingStaleJob {
});
for (const calendarChannel of calendarChannels) {
if (
calendarChannel.syncStageStartedAt &&
isSyncStale(calendarChannel.syncStageStartedAt)
) {
if (isSyncStale(calendarChannel.syncStageStartedAt)) {
await this.calendarChannelSyncStatusService.resetSyncStageStartedAt(
[calendarChannel.id],
workspaceId,
@@ -1,6 +1,12 @@
import { isDefined } from 'twenty-shared/utils';
import { CALENDAR_IMPORT_ONGOING_SYNC_TIMEOUT } from 'src/modules/calendar/calendar-event-import-manager/constants/calendar-import-ongoing-sync-timeout.constant';
export const isSyncStale = (syncStageStartedAt: string): boolean => {
export const isSyncStale = (syncStageStartedAt?: string | null): boolean => {
if (!isDefined(syncStageStartedAt)) {
return false;
}
const syncStageStartedTime = new Date(syncStageStartedAt).getTime();
if (isNaN(syncStageStartedTime)) {
@@ -182,6 +182,7 @@ export class CalendarChannelSyncStatusService {
await calendarChannelRepository.update(calendarChannelIds, {
syncStage: CalendarChannelSyncStage.CALENDAR_EVENTS_IMPORT_ONGOING,
syncStatus: CalendarChannelSyncStatus.ONGOING,
syncStageStartedAt: new Date().toISOString(),
});
}, authContext);
}
@@ -199,6 +199,7 @@ export class MessageChannelSyncStatusService {
await messageChannelRepository.update(messageChannelIds, {
syncStage: MessageChannelSyncStage.MESSAGE_LIST_FETCH_ONGOING,
syncStatus: MessageChannelSyncStatus.ONGOING,
syncStageStartedAt: new Date().toISOString(),
});
}, authContext);
}
@@ -277,6 +278,7 @@ export class MessageChannelSyncStatusService {
await messageChannelRepository.update(messageChannelIds, {
syncStage: MessageChannelSyncStage.MESSAGES_IMPORT_ONGOING,
syncStatus: MessageChannelSyncStatus.ONGOING,
syncStageStartedAt: new Date().toISOString(),
});
}, authContext);
@@ -54,10 +54,7 @@ export class MessagingOngoingStaleJob {
});
for (const messageChannel of messageChannels) {
if (
messageChannel.syncStageStartedAt &&
isSyncStale(messageChannel.syncStageStartedAt)
) {
if (isSyncStale(messageChannel.syncStageStartedAt)) {
await this.messageChannelSyncStatusService.resetSyncStageStartedAt(
[messageChannel.id],
workspaceId,
@@ -24,7 +24,19 @@ describe('isSyncStale', () => {
expect(result).toBe(false);
});
it('should return false if syncStageStartedAt is invalid', () => {
it('should return false if syncStageStartedAt is undefined', () => {
const result = isSyncStale(undefined);
expect(result).toBe(false);
});
it('should return false if syncStageStartedAt is null', () => {
const result = isSyncStale(null);
expect(result).toBe(false);
});
it('should throw an error if syncStageStartedAt is invalid', () => {
const syncStageStartedAt = 'invalid-date';
expect(() => {
@@ -1,6 +1,12 @@
import { isDefined } from 'twenty-shared/utils';
import { MESSAGING_IMPORT_ONGOING_SYNC_TIMEOUT } from 'src/modules/messaging/message-import-manager/constants/messaging-import-ongoing-sync-timeout.constant';
export const isSyncStale = (syncStageStartedAt: string): boolean => {
export const isSyncStale = (syncStageStartedAt?: string | null): boolean => {
if (!isDefined(syncStageStartedAt)) {
return false;
}
const syncStageStartedTime = new Date(syncStageStartedAt).getTime();
if (isNaN(syncStageStartedTime)) {