Skip to content

Commit

Permalink
Merge pull request #1920 from Accenture/feature/1919-reroute-stop-jou…
Browse files Browse the repository at this point in the history
…rney-to-pause-for-transactional-send-journeys

feature/1919 reroute stop journey to pause journey for transactional send journeys
  • Loading branch information
JoernBerkefeld authored Dec 6, 2024
2 parents b68adc3 + be0ccbe commit d31857c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 25 deletions.
2 changes: 1 addition & 1 deletion @types/lib/metadataTypes/Journey.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 45 additions & 24 deletions lib/metadataTypes/Journey.js
Original file line number Diff line number Diff line change
Expand Up @@ -2336,6 +2336,7 @@ class Journey extends MetadataType {
let version;
const endpoint = '/interaction/v1/interactions/stop/';
const stoppedKeyArr = [];
const pauseTransactionalKeyArr = [];
const apiLimit = pLimit(20);
const journeyCache = await this.retrieveForCache();

Expand All @@ -2344,33 +2345,53 @@ class Journey extends MetadataType {
apiLimit(async () => {
[key, version] = key.split('/');
if (journeyCache.metadata[key]) {
version ||= journeyCache.metadata[key].version;
if (version === '*') {
Util.logger.warn(
` ☇ skipping ${this.definition.type} ${key}: Cannot stop all versions at once. The highest version is ${journeyCache.metadata[key].version}`
);
return;
}
try {
await this.client.rest.post(
endpoint +
journeyCache.metadata[key].id +
`?versionNumber=${version}`,
{}
);
Util.logger.info(
` - Stopped ${this.definition.type} ${key}/${version}`
);
stoppedKeyArr.push(key);
} catch (ex) {
Util.logger.error(
` - Stopping ${this.definition.type} ${key} failed: ${ex.message}`
);
switch (journeyCache.metadata[key].definitionType) {
case 'Transactional': {
// transactional send journeys cannot be "stopped" but only "paused"
pauseTransactionalKeyArr.push(key);
break;
}
case 'Multistep': {
version ||= journeyCache.metadata[key].version;
if (version === '*') {
Util.logger.warn(
` ☇ skipping ${this.definition.type} ${key} / ${journeyCache.metadata[key].name}: Cannot stop all versions at once. The highest version is ${journeyCache.metadata[key].version}`
);
return;
}
try {
await this.client.rest.post(
endpoint +
journeyCache.metadata[key].id +
`?versionNumber=${version}`,
{}
);
Util.logger.info(
` - Stopped ${this.definition.type} ${key}/${version} / ${journeyCache.metadata[key].name}`
);
stoppedKeyArr.push(key);
} catch (ex) {
Util.logger.error(
` - Stopping ${this.definition.type} ${key} / ${journeyCache.metadata[key].name} failed: ${ex.message}`
);
}
break;
}
default: {
Util.logger.error(
` - Stopping ${this.definition.type} ${key} / ${journeyCache.metadata[key].name} failed: Unsupported definitionType '${journeyCache.metadata[key].definitionType}'`
);
}
}
} else {
Util.logger.error(
` - Stopping ${this.definition.type} ${key} failed: Journey not found on server`
);
}
})
)
);
stoppedKeyArr.push(...(await this.pause(pauseTransactionalKeyArr)));

return stoppedKeyArr;
}
Expand Down Expand Up @@ -2443,7 +2464,7 @@ class Journey extends MetadataType {
}
default: {
Util.logger.error(
` - Pausing ${this.definition.type} ${key} / ${journeyCache.metadata[key].name} failed: Unknown definitionType '${journeyCache.metadata[key].definitionType}'`
` - Pausing ${this.definition.type} ${key} / ${journeyCache.metadata[key].name} failed: Unsupported definitionType '${journeyCache.metadata[key].definitionType}'`
);
}
}
Expand Down Expand Up @@ -2528,7 +2549,7 @@ class Journey extends MetadataType {
}
default: {
Util.logger.error(
` - Resuming ${this.definition.type} ${key} / ${journeyCache.metadata[key].name} failed failed: Unknown definitionType '${journeyCache.metadata[key].definitionType}'`
` - Resuming ${this.definition.type} ${key} / ${journeyCache.metadata[key].name} failed: Unsupported definitionType '${journeyCache.metadata[key].definitionType}'`
);
}
}
Expand Down

0 comments on commit d31857c

Please sign in to comment.