Skip to content

Commit

Permalink
#1921: refactoring to bundle calls for refreshing triggeredSends
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed Dec 7, 2024
1 parent e419136 commit 9e28d4c
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions lib/metadataTypes/Journey.js
Original file line number Diff line number Diff line change
Expand Up @@ -2589,6 +2589,7 @@ class Journey extends MetadataType {
Util.logger.info(`Refreshing ${keyArr.length} ${this.definition.typeName}...`);
Util.logger.debug(`Refreshing keys: ${keyArr.join(', ')}`);
const refreshedKeyArr = [];
const tsKeys = [];
const rateLimit = pLimit(10);
await Promise.all(
keyArr.map((key) =>
Expand Down Expand Up @@ -2631,52 +2632,43 @@ class Journey extends MetadataType {
if (allActiveVersions.length) {
Util.logger.info(
Util.getGrayMsg(
` - Paused/Published version: ` +
` - journey ${key} Paused/Published versions: ` +
allActiveVersions.join(', ')
)
);
// get TS keys from email activities of paused/published versions
const rateLimitActivities = pLimit(2);
const tsKeys = (
await Promise.all(
allActiveVersions.map((version) =>
rateLimitActivities(async () => {
const journey = await this.client.rest.get(
'/interaction/v1/interactions/' +
journeyCache.metadata[key]?.id +
'?extras=activities&versionNumber=' +
version
);
// return all triggeredSends
return journey.activities
.filter(
(activity) =>
activity.type === 'EMAILV2' &&
activity.configurationArguments
?.triggeredSendKey
)
.map(
(activity) =>
activity.configurationArguments
?.triggeredSendKey
tsKeys.push(
...(
await Promise.all(
allActiveVersions.map((version) =>
rateLimitActivities(async () => {
const journey = await this.client.rest.get(
'/interaction/v1/interactions/' +
journeyCache.metadata[key]?.id +
'?extras=activities&versionNumber=' +
version
);
})
// return all triggeredSends
return journey.activities
.filter(
(activity) =>
activity.type === 'EMAILV2' &&
activity.configurationArguments
?.triggeredSendKey
)
.map(
(activity) =>
activity.configurationArguments
?.triggeredSendKey
);
})
)
)
)
).flat();

// refresh TriggeredSends
TriggeredSend.buObject = this.buObject;
TriggeredSend.client = this.client;
TriggeredSend.properties = this.properties;
// hard-refresh all triggeredSends even if the TS was paused (inactive) before
const refreshedTsKeys = await TriggeredSend.refresh(
tsKeys,
false
).flat()
);
if (refreshedTsKeys.length === tsKeys.length) {
refreshedKeyArr.push(key);
}

refreshedKeyArr.push(key);
} else {
Util.logger.error(
` ☇ skipping refresh of ${this.definition.type} ${key}: no published/paused versions found`
Expand All @@ -2694,6 +2686,14 @@ class Journey extends MetadataType {
})
)
);

// refresh TriggeredSends
TriggeredSend.buObject = this.buObject;
TriggeredSend.client = this.client;
TriggeredSend.properties = this.properties;
// hard-refresh all triggeredSends even if the TS was paused (inactive) before
await TriggeredSend.refresh(tsKeys, false);

Util.logger.info(
`Refreshed ${refreshedKeyArr.length} of ${keyArr.length} ${this.definition.type}`
);
Expand Down

0 comments on commit 9e28d4c

Please sign in to comment.