@@ -8,19 +8,29 @@ import { MessageQueueJob } from 'src/engine/integrations/message-queue/interface
8
8
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity' ;
9
9
import { DataSourceEntity } from 'src/engine/metadata-modules/data-source/data-source.entity' ;
10
10
import {
11
- GmailPartialSyncJobData ,
12
- GmailPartialSyncJob ,
13
- } from 'src/modules/messaging/jobs/gmail-partial-sync .job' ;
11
+ GmailPartialMessageListFetchJobData ,
12
+ GmailPartialMessageListFetchJob ,
13
+ } from 'src/modules/messaging/jobs/gmail-partial-message-list-fetch .job' ;
14
14
import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants' ;
15
15
import { MessageQueueService } from 'src/engine/integrations/message-queue/services/message-queue.service' ;
16
16
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator' ;
17
17
import { MessageChannelRepository } from 'src/modules/messaging/repositories/message-channel.repository' ;
18
18
import { MessageChannelWorkspaceEntity } from 'src/modules/messaging/standard-objects/message-channel.workspace-entity' ;
19
19
import { EnvironmentService } from 'src/engine/integrations/environment/environment.service' ;
20
+ import {
21
+ FeatureFlagEntity ,
22
+ FeatureFlagKeys ,
23
+ } from 'src/engine/core-modules/feature-flag/feature-flag.entity' ;
24
+ import {
25
+ GmailMessageListFetchJobData ,
26
+ GmailMessageListFetchJob ,
27
+ } from 'src/modules/messaging/jobs/gmail-message-list-fetch.job' ;
20
28
21
29
@Injectable ( )
22
- export class GmailPartialSyncCronJob implements MessageQueueJob < undefined > {
23
- private readonly logger = new Logger ( GmailPartialSyncCronJob . name ) ;
30
+ export class GmailMessageListFetchCronJob
31
+ implements MessageQueueJob < undefined >
32
+ {
33
+ private readonly logger = new Logger ( GmailMessageListFetchCronJob . name ) ;
24
34
25
35
constructor (
26
36
@InjectRepository ( Workspace , 'core' )
@@ -32,6 +42,8 @@ export class GmailPartialSyncCronJob implements MessageQueueJob<undefined> {
32
42
@InjectObjectMetadataRepository ( MessageChannelWorkspaceEntity )
33
43
private readonly messageChannelRepository : MessageChannelRepository ,
34
44
private readonly environmentService : EnvironmentService ,
45
+ @InjectRepository ( FeatureFlagEntity , 'core' )
46
+ private readonly featureFlagRepository : Repository < FeatureFlagEntity > ,
35
47
) { }
36
48
37
49
async handle ( ) : Promise < void > {
@@ -57,11 +69,20 @@ export class GmailPartialSyncCronJob implements MessageQueueJob<undefined> {
57
69
) ;
58
70
59
71
for ( const workspaceId of workspaceIdsWithDataSources ) {
60
- await this . enqueuePartialSyncs ( workspaceId ) ;
72
+ await this . enqueueSyncs ( workspaceId ) ;
61
73
}
62
74
}
63
75
64
- private async enqueuePartialSyncs ( workspaceId : string ) : Promise < void > {
76
+ private async enqueueSyncs ( workspaceId : string ) : Promise < void > {
77
+ const isGmailSyncV2EnabledFeatureFlag =
78
+ await this . featureFlagRepository . findOneBy ( {
79
+ workspaceId : workspaceId ,
80
+ key : FeatureFlagKeys . IsGmailSyncV2Enabled ,
81
+ value : true ,
82
+ } ) ;
83
+
84
+ const isGmailSyncV2Enabled = isGmailSyncV2EnabledFeatureFlag ?. value ;
85
+
65
86
try {
66
87
const messageChannels =
67
88
await this . messageChannelRepository . getAll ( workspaceId ) ;
@@ -71,16 +92,29 @@ export class GmailPartialSyncCronJob implements MessageQueueJob<undefined> {
71
92
continue ;
72
93
}
73
94
74
- await this . messageQueueService . add < GmailPartialSyncJobData > (
75
- GmailPartialSyncJob . name ,
76
- {
77
- workspaceId,
78
- connectedAccountId : messageChannel . connectedAccountId ,
79
- } ,
80
- {
81
- retryLimit : 2 ,
82
- } ,
83
- ) ;
95
+ if ( isGmailSyncV2Enabled ) {
96
+ await this . messageQueueService . add < GmailMessageListFetchJobData > (
97
+ GmailMessageListFetchJob . name ,
98
+ {
99
+ workspaceId,
100
+ connectedAccountId : messageChannel . connectedAccountId ,
101
+ } ,
102
+ {
103
+ retryLimit : 2 ,
104
+ } ,
105
+ ) ;
106
+ } else {
107
+ await this . messageQueueService . add < GmailPartialMessageListFetchJobData > (
108
+ GmailPartialMessageListFetchJob . name ,
109
+ {
110
+ workspaceId,
111
+ connectedAccountId : messageChannel . connectedAccountId ,
112
+ } ,
113
+ {
114
+ retryLimit : 2 ,
115
+ } ,
116
+ ) ;
117
+ }
84
118
}
85
119
} catch ( error ) {
86
120
this . logger . error (
0 commit comments