Skip to content

Commit

Permalink
Merge pull request #1765 from Accenture/feature/1746-enhance-pause-jo…
Browse files Browse the repository at this point in the history
…urney-to-support-transactional-send-journeys

feature/1746 support pausing transactional send journeys
  • Loading branch information
JoernBerkefeld authored Dec 6, 2024
2 parents b92241a + c96b26f commit b68adc3
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 34 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.

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

Expand All @@ -2392,29 +2391,72 @@ 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(` - Paused ${this.definition.type} ${key}/${version}`);
stoppedKeyArr.push(key);
} catch (ex) {
if (journeyCache.metadata[key].status !== 'Published') {
Util.logger.error(
` - Pausing ${this.definition.type} ${key} failed: ${ex.message}`
` - 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 {
const response = await this.client.rest.post(
'/interaction/v1/interactions/transactional/pause',
{ definitionId: journeyCache.metadata[key].id }
);
if (response.errors?.length) {
throw new Error(JSON.stringify(response));
} else {
Util.logger.info(
` - Paused ${this.definition.type} ${key} / ${journeyCache.metadata[key].name}`
);
pausedKeyArr.push(key);
}
} catch (ex) {
Util.logger.error(
` - Pausing ${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(
'/interaction/v1/interactions/pause/' +
journeyCache.metadata[key].id +
(version === '*'
? '?allVersions=true'
: `?versionNumber=${version}`),
{}
);
Util.logger.info(
` - Paused ${this.definition.type} ${key}/${version} / ${journeyCache.metadata[key].name}`
);
pausedKeyArr.push(key);
} catch (ex) {
Util.logger.error(
` - Pausing ${this.definition.type} ${key} / ${journeyCache.metadata[key].name} failed: ${ex.message}`
);
}
break;
}
default: {
Util.logger.error(
` - 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 @@ -2434,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 b68adc3

Please sign in to comment.