Skip to content

Commit

Permalink
#1746: upgrade pause and resume to support transactional send journeys
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed Dec 6, 2024
1 parent c56e11d commit c96b26f
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 22 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.

93 changes: 72 additions & 21 deletions lib/metadataTypes/Journey.js
Original file line number Diff line number Diff line change
Expand Up @@ -2382,7 +2382,7 @@ class Journey extends MetadataType {
*/
static async pause(keyArr) {
let version;
const stoppedKeyArr = [];
const pausedKeyArr = [];
const apiLimit = pLimit(20);
const journeyCache = await this.retrieveForCache();

Expand All @@ -2391,6 +2391,12 @@ class Journey extends MetadataType {
apiLimit(async () => {
[key, version] = key.split('/');
if (journeyCache.metadata[key]) {
if (journeyCache.metadata[key].status !== 'Published') {
Util.logger.error(
` - Pausing ${this.definition.type} ${key} / ${journeyCache.metadata[key].name} failed: Cannot pause a journey in status ${journeyCache.metadata[key].status}`
);
return;
}
switch (journeyCache.metadata[key].definitionType) {
case 'Transactional': {
try {
Expand All @@ -2404,7 +2410,7 @@ class Journey extends MetadataType {
Util.logger.info(
` - Paused ${this.definition.type} ${key} / ${journeyCache.metadata[key].name}`
);
stoppedKeyArr.push(key);
pausedKeyArr.push(key);
}
} catch (ex) {
Util.logger.error(
Expand All @@ -2427,7 +2433,7 @@ class Journey extends MetadataType {
Util.logger.info(
` - Paused ${this.definition.type} ${key}/${version} / ${journeyCache.metadata[key].name}`
);
stoppedKeyArr.push(key);
pausedKeyArr.push(key);
} catch (ex) {
Util.logger.error(
` - Pausing ${this.definition.type} ${key} / ${journeyCache.metadata[key].name} failed: ${ex.message}`
Expand All @@ -2437,16 +2443,20 @@ class Journey extends MetadataType {
}
default: {
Util.logger.error(
` - Pausing ${this.definition.type} ${key} failed: Unknown definitionType '${journeyCache.metadata[key].definitionType}'`
` - Pausing ${this.definition.type} ${key} / ${journeyCache.metadata[key].name} failed: Unknown definitionType '${journeyCache.metadata[key].definitionType}'`
);
}
}
} else {
Util.logger.error(
` - Pausing ${this.definition.type} ${key} failed: Journey not found on server`
);
}
})
)
);

return stoppedKeyArr;
return pausedKeyArr;
}
/**
* resumes selected journey versions
Expand All @@ -2466,25 +2476,66 @@ class Journey extends MetadataType {
apiLimit(async () => {
[key, version] = key.split('/');
if (journeyCache.metadata[key]) {
version ||= journeyCache.metadata[key].version;
try {
await this.client.rest.post(
endpoint +
journeyCache.metadata[key].id +
(version === '*'
? '?allVersions=true'
: `?versionNumber=${version}`),
{}
);
Util.logger.info(
` - Resumed ${this.definition.type} ${key}/${version}`
);
resumedKeyArr.push(key);
} catch (ex) {
if (journeyCache.metadata[key].status !== 'Paused') {
Util.logger.error(
` - Resuming ${this.definition.type} ${key} failed: ${ex.message}`
` - Resuming ${this.definition.type} ${key} / ${journeyCache.metadata[key].name} failed: Cannot pause a journey in status ${journeyCache.metadata[key].status}`
);
return;
}
switch (journeyCache.metadata[key].definitionType) {
case 'Transactional': {
try {
const response = await this.client.rest.post(
'/interaction/v1/interactions/transactional/resume',
{ definitionId: journeyCache.metadata[key].id }
);
if (response.errors?.length) {
throw new Error(JSON.stringify(response));
} else {
Util.logger.info(
` - Resumed ${this.definition.type} ${key} / ${journeyCache.metadata[key].name}`
);
resumedKeyArr.push(key);
}
} catch (ex) {
Util.logger.error(
` - Resuming ${this.definition.type} ${key} / ${journeyCache.metadata[key].name} failed: ${ex.message}`
);
}
break;
}
case 'Multistep': {
version ||= journeyCache.metadata[key].version;
try {
await this.client.rest.post(
endpoint +
journeyCache.metadata[key].id +
(version === '*'
? '?allVersions=true'
: `?versionNumber=${version}`),
{}
);
Util.logger.info(
` - Resumed ${this.definition.type} ${key}/${version}`
);
resumedKeyArr.push(key);
} catch (ex) {
Util.logger.error(
` - Resuming ${this.definition.type} ${key} / ${journeyCache.metadata[key].name} failed: ${ex.message}`
);
}
break;
}
default: {
Util.logger.error(
` - Resuming ${this.definition.type} ${key} / ${journeyCache.metadata[key].name} failed failed: Unknown definitionType '${journeyCache.metadata[key].definitionType}'`
);
}
}
} else {
Util.logger.error(
` - Resuming ${this.definition.type} ${key} failed: Journey not found on server`
);
}
})
)
Expand Down

0 comments on commit c96b26f

Please sign in to comment.