Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions components/hubspot/sources/new-deal-in-stage/new-deal-in-stage.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import {
import common from "../common/common.mjs";
import sampleEmit from "./test-event.mjs";

const MAX_INITIAL_EVENTS = 25;

export default {
...common,
key: "hubspot-new-deal-in-stage",
name: "New Deal In Stage",
description: "Emit new event for each new deal in a stage.",
version: "0.0.41",
version: "0.1.0",
dedupe: "unique",
type: "source",
props: {
Expand Down Expand Up @@ -87,7 +89,7 @@ export default {
object: "deals",
};
},
async processDeals(params, after) {
async processDeals(params, after, initialEventsEmitted) {
let maxTs = after || 0;

do {
Expand All @@ -111,19 +113,27 @@ export default {
maxTs = ts;
this._setAfter(ts);
}
if (!after && ++initialEventsEmitted >= MAX_INITIAL_EVENTS) {
return initialEventsEmitted;
}
}
}

// first run, get only first page
if (!after) {
return;
break;
}
} while (params.after);
return initialEventsEmitted;
},
async processResults(after) {
let initialEventsEmitted = 0;
for (const stage of this.stages) {
const params = this.getStageParams(stage);
await this.processDeals(params, after);
initialEventsEmitted += await this.processDeals(params, after, initialEventsEmitted);
if (initialEventsEmitted >= MAX_INITIAL_EVENTS) {
return;
}
}
},
getOwner(ownerId) {
Expand Down
Loading