Skip to content

Commit b4a7915

Browse files
authored
Hubspot New Deal in Stage - limit initial events (#18469)
* Adding max initial events to "New Deal in Stage" * Adjusting new-deal-in-stage * Adjusting subsequent runs of 'new deal in stage' * Version bumps * Version bump
1 parent cd835d7 commit b4a7915

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

components/hubspot/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/hubspot",
3-
"version": "1.7.11",
3+
"version": "1.7.12",
44
"description": "Pipedream Hubspot Components",
55
"main": "hubspot.app.mjs",
66
"keywords": [

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

Lines changed: 29 additions & 15 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.41",
16+
version: "0.1.0",
1517
dedupe: "unique",
1618
type: "source",
1719
props: {
@@ -59,16 +61,26 @@ export default {
5961
getParams() {
6062
return null;
6163
},
62-
getStageParams(stage) {
63-
const filter = {
64-
propertyName: "dealstage",
65-
operator: "EQ",
66-
value: stage,
67-
};
64+
getAllStagesParams(after) {
65+
const filters = [
66+
{
67+
propertyName: "dealstage",
68+
operator: "IN",
69+
values: this.stages,
70+
},
71+
];
72+
73+
// Add time filter for subsequent runs to only get recently modified deals
74+
if (after) {
75+
filters.push({
76+
propertyName: "hs_lastmodifieddate",
77+
operator: "GT",
78+
value: after,
79+
});
80+
}
81+
6882
const filterGroup = {
69-
filters: [
70-
filter,
71-
],
83+
filters,
7284
};
7385
return {
7486
data: {
@@ -89,6 +101,7 @@ export default {
89101
},
90102
async processDeals(params, after) {
91103
let maxTs = after || 0;
104+
let initialEventsEmitted = 0;
92105

93106
do {
94107
const results = await this.hubspot.searchCRM(params);
@@ -111,20 +124,21 @@ export default {
111124
maxTs = ts;
112125
this._setAfter(ts);
113126
}
127+
if (!after && ++initialEventsEmitted >= MAX_INITIAL_EVENTS) {
128+
return;
129+
}
114130
}
115131
}
116132

117133
// first run, get only first page
118134
if (!after) {
119-
return;
135+
break;
120136
}
121137
} while (params.after);
122138
},
123139
async processResults(after) {
124-
for (const stage of this.stages) {
125-
const params = this.getStageParams(stage);
126-
await this.processDeals(params, after);
127-
}
140+
const params = this.getAllStagesParams(after);
141+
await this.processDeals(params, after);
128142
},
129143
getOwner(ownerId) {
130144
return this.hubspot.makeRequest({

0 commit comments

Comments
 (0)