Skip to content

Commit

Permalink
Atualização de logs de oportunidade (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
mclmorais committed Jun 14, 2024
1 parent daddc9a commit 303612d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 14 deletions.
17 changes: 17 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "npm run build",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "always"
},
}
]
}
2 changes: 1 addition & 1 deletion dist/index.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ declare class CrmClient {
static getInstance(): CrmClient;
static init(projectId: string, keyFilename: string, loggerInstance: Logger, errorConverter: ErrorConverter, customTopicName?: string): void;
sendNotification(recipientInfo: CrmRecipientInfo, templateName: string, templateValues: Record<string, unknown>, settings?: CrmNotificationSettings): Promise<void>;
processOpportunity(opportunityId: string): Promise<void>;
processOpportunity(opportunityId: string, tracerMessageId: string): Promise<void>;
}

export { CrmClient, type CrmMessage, type CrmNotificationSettings, type CrmRecipientInfo, type NotificationChannel };
2 changes: 1 addition & 1 deletion dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ declare class CrmClient {
static getInstance(): CrmClient;
static init(projectId: string, keyFilename: string, loggerInstance: Logger, errorConverter: ErrorConverter, customTopicName?: string): void;
sendNotification(recipientInfo: CrmRecipientInfo, templateName: string, templateValues: Record<string, unknown>, settings?: CrmNotificationSettings): Promise<void>;
processOpportunity(opportunityId: string): Promise<void>;
processOpportunity(opportunityId: string, tracerMessageId: string): Promise<void>;
}

export { CrmClient, type CrmMessage, type CrmNotificationSettings, type CrmRecipientInfo, type NotificationChannel };
10 changes: 6 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,17 @@ var CrmClient = class _CrmClient {
}
});
}
processOpportunity(opportunityId) {
processOpportunity(opportunityId, tracerMessageId) {
return __async(this, null, function* () {
if (!this.opportunityTopicName) {
throw new Error("CRM opportunity topic name not provided. Add the CRM_OPPORTUNITY_TOPIC environment variable.");
}
const message = { opportunityId, tracerMessageId: (0, import_uuid.v4)() };
const message = { opportunityId, tracerMessageId };
try {
const messageId = yield this.pubsubInstance.topic(this.opportunityTopicName).publishMessage({ json: message });
this.loggerInstance.Info({
event: "publish-opportunity-processing",
event: "opportunity-processing",
step: "message-publishing",
status: "success",
stage: "emitter",
topic: this.opportunityTopicName,
Expand All @@ -174,7 +175,8 @@ var CrmClient = class _CrmClient {
});
} catch (error) {
this.loggerInstance.Info({
event: "publish-message",
event: "opportunity-processing",
step: "message-publishing",
status: "failure",
stage: "emitter",
// destination,
Expand Down
10 changes: 6 additions & 4 deletions dist/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,17 @@ var CrmClient = class _CrmClient {
}
});
}
processOpportunity(opportunityId) {
processOpportunity(opportunityId, tracerMessageId) {
return __async(this, null, function* () {
if (!this.opportunityTopicName) {
throw new Error("CRM opportunity topic name not provided. Add the CRM_OPPORTUNITY_TOPIC environment variable.");
}
const message = { opportunityId, tracerMessageId: uuidv4() };
const message = { opportunityId, tracerMessageId };
try {
const messageId = yield this.pubsubInstance.topic(this.opportunityTopicName).publishMessage({ json: message });
this.loggerInstance.Info({
event: "publish-opportunity-processing",
event: "opportunity-processing",
step: "message-publishing",
status: "success",
stage: "emitter",
topic: this.opportunityTopicName,
Expand All @@ -153,7 +154,8 @@ var CrmClient = class _CrmClient {
});
} catch (error) {
this.loggerInstance.Info({
event: "publish-message",
event: "opportunity-processing",
step: "message-publishing",
status: "failure",
stage: "emitter",
// destination,
Expand Down
10 changes: 6 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,19 @@ export class CrmClient {
}
}

public async processOpportunity (opportunityId: string): Promise<void> {
public async processOpportunity (opportunityId: string, tracerMessageId: string): Promise<void> {
if (!this.opportunityTopicName) {
throw new Error('CRM opportunity topic name not provided. Add the CRM_OPPORTUNITY_TOPIC environment variable.')
}
const message = { opportunityId, tracerMessageId: uuidv4() }
const message = { opportunityId, tracerMessageId }
try {
const messageId = await this.pubsubInstance
.topic(this.opportunityTopicName)
.publishMessage({ json: message })

this.loggerInstance.Info({
event: 'publish-opportunity-processing',
event: 'opportunity-processing',
step: 'message-publishing',
status: 'success',
stage: 'emitter',
topic: this.opportunityTopicName,
Expand All @@ -152,7 +153,8 @@ export class CrmClient {
} catch (error) {
// trace logging
this.loggerInstance.Info({
event: 'publish-message',
event: 'opportunity-processing',
step: 'message-publishing',
status: 'failure',
stage: 'emitter',
// destination,
Expand Down

0 comments on commit 303612d

Please sign in to comment.