Skip to content

Commit dfb21bb

Browse files
committed
Adjusting new-deal-in-stage
1 parent 34cd63a commit dfb21bb

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

components/hubspot/sources/new-deal-in-stage/new-deal-in-stage.mjs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import {
66
import common from "../common/common.mjs";
77
import sampleEmit from "./test-event.mjs";
88

9+
const MAX_INITIAL_EVENTS = 25;
10+
911
export default {
1012
...common,
1113
key: "hubspot-new-deal-in-stage",
1214
name: "New Deal In Stage",
1315
description: "Emit new event for each new deal in a stage.",
14-
version: "0.0.42",
16+
version: "0.1.0",
1517
dedupe: "unique",
1618
type: "source",
1719
props: {
@@ -87,10 +89,8 @@ export default {
8789
object: "deals",
8890
};
8991
},
90-
async processDeals(params, after) {
92+
async processDeals(params, after, initialEventsEmitted) {
9193
let maxTs = after || 0;
92-
let initialEventsEmitted = 0;
93-
const maxInitialEvents = 25;
9494

9595
do {
9696
const results = await this.hubspot.searchCRM(params);
@@ -113,22 +113,27 @@ export default {
113113
maxTs = ts;
114114
this._setAfter(ts);
115115
}
116-
if (!after && ++initialEventsEmitted >= maxInitialEvents) {
117-
return;
116+
if (!after && ++initialEventsEmitted >= MAX_INITIAL_EVENTS) {
117+
return initialEventsEmitted;
118118
}
119119
}
120120
}
121121

122122
// first run, get only first page
123123
if (!after) {
124-
return;
124+
break;
125125
}
126126
} while (params.after);
127+
return initialEventsEmitted;
127128
},
128129
async processResults(after) {
130+
let initialEventsEmitted = 0;
129131
for (const stage of this.stages) {
130132
const params = this.getStageParams(stage);
131-
await this.processDeals(params, after);
133+
initialEventsEmitted += await this.processDeals(params, after, initialEventsEmitted);
134+
if (initialEventsEmitted >= MAX_INITIAL_EVENTS) {
135+
return;
136+
}
132137
}
133138
},
134139
getOwner(ownerId) {

0 commit comments

Comments
 (0)