@@ -48,6 +48,8 @@ export class Controller {
48
48
null ;
49
49
private pubSubIntegrationEventsClient : PubSubClient < PubSubIntegrationsEventMessage > | null =
50
50
null ;
51
+ private additionalPubSubContactStreamingClient : PubSubClient < PubSubContactsMessage > | null =
52
+ null ;
51
53
private integrationName : string = 'UNKNOWN' ;
52
54
53
55
// used for garbage collection reasons, to prevent long running promises from getting canceled
@@ -81,6 +83,7 @@ export class Controller {
81
83
const {
82
84
PUBSUB_TOPIC_NAME : topicNameLegacy ,
83
85
PUBSUB_TOPIC_NAME_CONTACT_STREAMING : topicName ,
86
+ PUBSUB_ADDITIONAL_TOPIC_NAME : additionalTopicName ,
84
87
} = process . env ;
85
88
86
89
const topicNameProvided = topicName ?? topicNameLegacy ;
@@ -90,11 +93,19 @@ export class Controller {
90
93
}
91
94
92
95
this . pubSubContactStreamingClient = new PubSubClient ( topicNameProvided ) ;
93
-
94
96
infoLogger (
95
97
'Controller' ,
96
98
`Initialized PubSub client for topic ${ topicNameProvided } ` ,
97
99
) ;
100
+ if ( additionalTopicName ) {
101
+ this . additionalPubSubContactStreamingClient = new PubSubClient (
102
+ additionalTopicName ,
103
+ ) ;
104
+ infoLogger (
105
+ 'Controller' ,
106
+ `Initialized PubSub client for topic ${ additionalTopicName } ` ,
107
+ ) ;
108
+ }
98
109
}
99
110
100
111
private initContactChanges ( ) {
@@ -105,7 +116,6 @@ export class Controller {
105
116
}
106
117
107
118
this . pubSubIntegrationEventsClient = new PubSubClient ( topicName ) ;
108
-
109
119
infoLogger (
110
120
'Controller' ,
111
121
`Initialized PubSub client for topic ${ topicName } ` ,
@@ -303,6 +313,7 @@ export class Controller {
303
313
throw new Error ( 'Invalid contacts received' ) ;
304
314
}
305
315
316
+ console . log ( 'Publishing contacts' , contacts . length ) ;
306
317
await this . pubSubContactStreamingClient ?. publishMessage (
307
318
{
308
319
userId,
@@ -315,6 +326,20 @@ export class Controller {
315
326
} ,
316
327
orderingKey ,
317
328
) ;
329
+
330
+ // todo: remove as soon as platypus goes live
331
+ await this . additionalPubSubContactStreamingClient ?. publishMessage (
332
+ {
333
+ userId,
334
+ timestamp,
335
+ contacts : contacts . map ( ( contact ) =>
336
+ sanitizeContact ( contact , providerConfig . locale ) ,
337
+ ) ,
338
+ state : PubSubContactsState . IN_PROGRESS ,
339
+ integrationName : this . integrationName ,
340
+ } ,
341
+ orderingKey ,
342
+ ) ;
318
343
} catch ( error ) {
319
344
errorLogger (
320
345
'streamContacts' ,
@@ -344,6 +369,17 @@ export class Controller {
344
369
345
370
const streamingPromise = streamContacts ( )
346
371
. then ( ( ) => {
372
+ this . additionalPubSubContactStreamingClient ?. publishMessage (
373
+ {
374
+ userId : providerConfig . userId ,
375
+ timestamp,
376
+ contacts : [ ] ,
377
+ state : PubSubContactsState . COMPLETE ,
378
+ integrationName : this . integrationName ,
379
+ } ,
380
+ orderingKey ,
381
+ ) ;
382
+
347
383
return this . pubSubContactStreamingClient ?. publishMessage (
348
384
{
349
385
userId : providerConfig . userId ,
@@ -362,6 +398,17 @@ export class Controller {
362
398
providerConfig . apiKey ,
363
399
error ,
364
400
) ;
401
+ this . additionalPubSubContactStreamingClient ?. publishMessage (
402
+ {
403
+ userId : providerConfig . userId ,
404
+ timestamp,
405
+ contacts : [ ] ,
406
+ state : PubSubContactsState . FAILED ,
407
+ integrationName : this . integrationName ,
408
+ } ,
409
+ orderingKey ,
410
+ ) ;
411
+
365
412
return this . pubSubContactStreamingClient ?. publishMessage (
366
413
{
367
414
userId : providerConfig . userId ,
0 commit comments