File tree Expand file tree Collapse file tree 2 files changed +11
-23
lines changed Expand file tree Collapse file tree 2 files changed +11
-23
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,6 @@ import {
14
14
ServerError ,
15
15
} from "." ;
16
16
import { calendarEventsSchema , contactsSchema } from "../schemas" ;
17
- import { isProduction } from "../util" ;
18
17
import { shouldSkipCallEvent } from "../util/call-event.util" ;
19
18
import { errorLogger , infoLogger } from "../util/logger.util" ;
20
19
import { parsePhoneNumber } from "../util/phone-number-utils" ;
@@ -54,12 +53,13 @@ export class Controller {
54
53
this . contactCache = contactCache ;
55
54
this . ajv = new Ajv ( ) ;
56
55
57
- const { PUBSUB_TOPIC_NAME : topicName } = process . env ;
56
+ if ( this . adapter . streamContacts ) {
57
+ const { PUBSUB_TOPIC_NAME : topicName } = process . env ;
58
58
59
- if ( isProduction ( ) && typeof this . adapter . streamContacts === "function" ) {
60
59
if ( ! topicName ) {
61
60
throw new Error ( "No pubsub topic name provided." ) ;
62
61
}
62
+
63
63
this . pubSubClient = new PubSubClient ( topicName ) ;
64
64
infoLogger (
65
65
"Controller" ,
@@ -215,7 +215,7 @@ export class Controller {
215
215
} catch ( error ) {
216
216
errorLogger (
217
217
"streamContacts" ,
218
- " Could not publish contacts" ,
218
+ ` Could not publish contacts` ,
219
219
providerConfig . apiKey ,
220
220
error
221
221
) ;
Original file line number Diff line number Diff line change 1
1
import { PubSub } from "@google-cloud/pubsub" ;
2
- import { errorLogger , infoLogger } from "../util" ;
3
2
import { PubSubContactsMessage } from "./pubsub-contacts-message.model" ;
4
3
5
4
export class PubSubClient {
@@ -12,24 +11,13 @@ export class PubSubClient {
12
11
}
13
12
14
13
async publishMessage ( message : PubSubContactsMessage ) {
15
- try {
16
- if ( ! this . topicName ) {
17
- throw new Error ( "No pubsub topic name provided." ) ;
18
- }
19
-
20
- const json = JSON . stringify ( message ) ;
21
- const dataBuffer = Buffer . from ( json ) ;
22
- const topic = this . client . topic ( this . topicName ) ;
23
- await topic . publishMessage ( { data : dataBuffer } ) ;
24
-
25
- infoLogger (
26
- PubSubClient . name ,
27
- `Published ${ message . contacts . length } contacts for user ${ message . userId } to topic ${ this . topicName } `
28
- ) ;
29
- } catch ( error ) {
30
- console . error ( error ) ;
31
- const message = ( error as Error ) . message ;
32
- errorLogger ( PubSubClient . name , `Could not publish to pubsub: ${ message } ` ) ;
14
+ if ( ! this . topicName ) {
15
+ throw new Error ( "No pubsub topic name provided." ) ;
33
16
}
17
+
18
+ const json = JSON . stringify ( message ) ;
19
+ const dataBuffer = Buffer . from ( json ) ;
20
+ const topic = this . client . topic ( this . topicName ) ;
21
+ await topic . publishMessage ( { data : dataBuffer } ) ;
34
22
}
35
23
}
You can’t perform that action at this time.
0 commit comments