Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/1746 support pause and resume for transactional send journeys #1765

Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading