Skip to content

Commit bbd265f

Browse files
committed
:small_adhesive_bandage: add additional topic Name for contact streaming
1 parent 411b538 commit bbd265f

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

src/models/controller.model.ts

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ export class Controller {
4848
null;
4949
private pubSubIntegrationEventsClient: PubSubClient<PubSubIntegrationsEventMessage> | null =
5050
null;
51+
private additionalPubSubContactStreamingClient: PubSubClient<PubSubContactsMessage> | null =
52+
null;
5153
private integrationName: string = 'UNKNOWN';
5254

5355
// used for garbage collection reasons, to prevent long running promises from getting canceled
@@ -81,6 +83,7 @@ export class Controller {
8183
const {
8284
PUBSUB_TOPIC_NAME: topicNameLegacy,
8385
PUBSUB_TOPIC_NAME_CONTACT_STREAMING: topicName,
86+
PUBSUB_ADDITIONAL_TOPIC_NAME: additionalTopicName,
8487
} = process.env;
8588

8689
const topicNameProvided = topicName ?? topicNameLegacy;
@@ -90,11 +93,19 @@ export class Controller {
9093
}
9194

9295
this.pubSubContactStreamingClient = new PubSubClient(topicNameProvided);
93-
9496
infoLogger(
9597
'Controller',
9698
`Initialized PubSub client for topic ${topicNameProvided}`,
9799
);
100+
if (additionalTopicName) {
101+
this.additionalPubSubContactStreamingClient = new PubSubClient(
102+
additionalTopicName,
103+
);
104+
infoLogger(
105+
'Controller',
106+
`Initialized PubSub client for topic ${additionalTopicName}`,
107+
);
108+
}
98109
}
99110

100111
private initContactChanges() {
@@ -105,7 +116,6 @@ export class Controller {
105116
}
106117

107118
this.pubSubIntegrationEventsClient = new PubSubClient(topicName);
108-
109119
infoLogger(
110120
'Controller',
111121
`Initialized PubSub client for topic ${topicName}`,
@@ -303,6 +313,7 @@ export class Controller {
303313
throw new Error('Invalid contacts received');
304314
}
305315

316+
console.log('Publishing contacts', contacts.length);
306317
await this.pubSubContactStreamingClient?.publishMessage(
307318
{
308319
userId,
@@ -315,6 +326,20 @@ export class Controller {
315326
},
316327
orderingKey,
317328
);
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+
);
318343
} catch (error) {
319344
errorLogger(
320345
'streamContacts',
@@ -344,6 +369,17 @@ export class Controller {
344369

345370
const streamingPromise = streamContacts()
346371
.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+
347383
return this.pubSubContactStreamingClient?.publishMessage(
348384
{
349385
userId: providerConfig.userId,
@@ -362,6 +398,17 @@ export class Controller {
362398
providerConfig.apiKey,
363399
error,
364400
);
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+
365412
return this.pubSubContactStreamingClient?.publishMessage(
366413
{
367414
userId: providerConfig.userId,

0 commit comments

Comments
 (0)