Skip to content

Commit 17fec66

Browse files
committed
move bottleneck to app file
1 parent 4546757 commit 17fec66

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

components/hubspot/hubspot.app.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ import {
1313
DEFAULT_PRODUCT_PROPERTIES,
1414
DEFAULT_LINE_ITEM_PROPERTIES,
1515
} from "./common/constants.mjs";
16+
import Bottleneck from "bottleneck";
17+
const limiter = new Bottleneck({
18+
minTime: 250, // 4 requests per second
19+
maxConcurrent: 1,
20+
});
21+
const axiosRateLimiter = limiter.wrap(axios);
1622

1723
export default {
1824
type: "app",
@@ -473,7 +479,7 @@ export default {
473479
params,
474480
...otherOpts
475481
}) {
476-
return axios($, {
482+
return axiosRateLimiter($, {
477483
url: `${BASE_URL}${api}${endpoint}`,
478484
headers: this._getHeaders(),
479485
data: data && this.trimStringValues(data),

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": "0.13.1",
3+
"version": "0.13.2",
44
"description": "Pipedream Hubspot Components",
55
"main": "hubspot.app.mjs",
66
"keywords": [

components/hubspot/sources/common/common.mjs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import hubspot from "../../hubspot.app.mjs";
2-
import Bottleneck from "bottleneck";
32
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
43

54
export default {
@@ -14,14 +13,6 @@ export default {
1413
},
1514
},
1615
methods: {
17-
_limiter() {
18-
return new Bottleneck({
19-
minTime: 250, // max 4 requests per second
20-
});
21-
},
22-
async _requestWithLimiter(limiter, resourceFn, params) {
23-
return limiter.schedule(async () => await resourceFn(params));
24-
},
2516
_getAfter() {
2617
return this.db.get("after") || new Date().setDate(new Date().getDate() - 1); // 1 day ago
2718
},
@@ -76,9 +67,8 @@ export default {
7667
async paginate(params, resourceFn, resultType = null, after = null) {
7768
let results = null;
7869
let maxTs = after || 0;
79-
const limiter = this._limiter();
8070
while (!results || params.after) {
81-
results = await this._requestWithLimiter(limiter, resourceFn, params);
71+
results = await resourceFn(params);
8272
if (results.paging) {
8373
params.after = results.paging.next.after;
8474
} else {
@@ -114,10 +104,9 @@ export default {
114104
let results, items;
115105
let count = 0;
116106
let maxTs = after || 0;
117-
const limiter = this._limiter();
118107
while (hasMore && (!limitRequest || count < limitRequest)) {
119108
count++;
120-
results = await this._requestWithLimiter(limiter, resourceFn, params);
109+
results = await resourceFn(params);
121110
hasMore = results.hasMore;
122111
if (hasMore) {
123112
params.offset = results.offset;

0 commit comments

Comments
 (0)