-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor calendar to use new sync statuses and stages (#6141)
- Refactor calendar modules and some messaging modules to better organize them by business rules and decouple them - Work toward a common architecture for the different calendar providers by introducing interfaces for the drivers - Modify cron job to use the new sync statuses and stages
- Loading branch information
1 parent
1c3ea9b
commit f458322
Showing
69 changed files
with
1,297 additions
and
881 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...twenty-server/src/engine/integrations/cache-storage/types/cache-storage-namespace.enum.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export enum CacheStorageNamespace { | ||
Messaging = 'messaging', | ||
Calendar = 'calendar', | ||
WorkspaceSchema = 'workspaceSchema', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...tests__/is-email-blocklisted.util.spec.ts → ...tests__/is-email-blocklisted.util.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...cipant/utils/is-email-blocklisted.util.ts → ...anager/utils/is-email-blocklisted.util.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
.../modules/calendar-messaging-participant/jobs/calendar-messaging-participant-job.module.ts
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
...ces/add-person-id-and-workspace-member-id/add-person-id-and-workspace-member-id.module.ts
This file was deleted.
Oops, something went wrong.
49 changes: 24 additions & 25 deletions
49
...ver/src/modules/calendar/blocklist-manager/jobs/blocklist-reimport-calendar-events.job.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,61 @@ | ||
import { Logger, Scope } from '@nestjs/common'; | ||
import { Scope } from '@nestjs/common'; | ||
|
||
import { Any } from 'typeorm'; | ||
|
||
import { Processor } from 'src/engine/integrations/message-queue/decorators/processor.decorator'; | ||
import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants'; | ||
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator'; | ||
import { ConnectedAccountRepository } from 'src/modules/connected-account/repositories/connected-account.repository'; | ||
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity'; | ||
import { Process } from 'src/engine/integrations/message-queue/decorators/process.decorator'; | ||
import { CalendarEventsImportService } from 'src/modules/calendar/calendar-event-import-manager/services/calendar-events-import.service'; | ||
import { InjectWorkspaceRepository } from 'src/engine/twenty-orm/decorators/inject-workspace-repository.decorator'; | ||
import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository'; | ||
import { | ||
CalendarChannelSyncStage, | ||
CalendarChannelWorkspaceEntity, | ||
} from 'src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity'; | ||
|
||
export type BlocklistReimportCalendarEventsJobData = { | ||
workspaceId: string; | ||
workspaceMemberId: string; | ||
handle: string; | ||
}; | ||
|
||
@Processor({ | ||
queueName: MessageQueue.calendarQueue, | ||
scope: Scope.REQUEST, | ||
}) | ||
export class BlocklistReimportCalendarEventsJob { | ||
private readonly logger = new Logger(BlocklistReimportCalendarEventsJob.name); | ||
|
||
constructor( | ||
@InjectObjectMetadataRepository(ConnectedAccountWorkspaceEntity) | ||
private readonly connectedAccountRepository: ConnectedAccountRepository, | ||
private readonly googleCalendarSyncService: CalendarEventsImportService, | ||
@InjectWorkspaceRepository(CalendarChannelWorkspaceEntity) | ||
private readonly calendarChannelRepository: WorkspaceRepository<CalendarChannelWorkspaceEntity>, | ||
) {} | ||
|
||
@Process(BlocklistReimportCalendarEventsJob.name) | ||
async handle(data: BlocklistReimportCalendarEventsJobData): Promise<void> { | ||
const { workspaceId, workspaceMemberId, handle } = data; | ||
|
||
this.logger.log( | ||
`Reimporting calendar events from handle ${handle} in workspace ${workspaceId} for workspace member ${workspaceMemberId}`, | ||
); | ||
const { workspaceId, workspaceMemberId } = data; | ||
|
||
const connectedAccount = | ||
const connectedAccounts = | ||
await this.connectedAccountRepository.getAllByWorkspaceMemberId( | ||
workspaceMemberId, | ||
workspaceId, | ||
); | ||
|
||
if (!connectedAccount || connectedAccount.length === 0) { | ||
this.logger.error( | ||
`No connected account found for workspace member ${workspaceMemberId} in workspace ${workspaceId}`, | ||
); | ||
|
||
if (!connectedAccounts || connectedAccounts.length === 0) { | ||
return; | ||
} | ||
|
||
await this.googleCalendarSyncService.processCalendarEventsImport( | ||
workspaceId, | ||
connectedAccount[0].id, | ||
handle, | ||
); | ||
|
||
this.logger.log( | ||
`Reimporting calendar events from ${handle} in workspace ${workspaceId} for workspace member ${workspaceMemberId} done`, | ||
await this.calendarChannelRepository.update( | ||
{ | ||
connectedAccountId: Any( | ||
connectedAccounts.map((connectedAccount) => connectedAccount.id), | ||
), | ||
}, | ||
{ | ||
syncStage: | ||
CalendarChannelSyncStage.FULL_CALENDAR_EVENT_LIST_FETCH_PENDING, | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.