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/1434 add resume journey via execute-method #1630

Merged
merged 3 commits into from
Sep 2, 2024
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
6 changes: 3 additions & 3 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,8 @@ yargs(hideBin(process.argv))
}
)
.command(
['execute <BU> [TYPE] [KEY]', 'exec', 'start'],
'executes the entity (query/journey/automation etc.)',
['execute <BU> [TYPE] [KEY]', 'exec', 'start', 'resume'],
'executes the entity',
(yargs) =>
yargs
.positional('BU', {
Expand Down Expand Up @@ -733,7 +733,7 @@ yargs(hideBin(process.argv))
}
)
.command(
['publish <BU> [TYPE] [KEY]'],
['publish <BU> [TYPE] [KEY]', 'activate'],
'publishes the entity',
(yargs) =>
yargs
Expand Down
44 changes: 44 additions & 0 deletions lib/metadataTypes/Journey.js
Original file line number Diff line number Diff line change
Expand Up @@ -2000,6 +2000,50 @@ class Journey extends MetadataType {

return stoppedKeyArr;
}
/**
* resumes selected journey versions
*
* @param {string[]} keyArr customerkey of the metadata
* @returns {Promise.<string[]>} Returns list of keys that were paused
*/
static async execute(keyArr) {
let version;
const endpoint = '/interaction/v1/interactions/resume/';
const resumedKeyArr = [];
const apiLimit = pLimit(20);
const journeyCache = await this.retrieveForCache();

await Promise.allSettled(
keyArr.map((key) =>
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) {
Util.logger.error(
` - Resuming ${this.definition.type} ${key} failed: ${ex.message}`
);
}
}
})
)
);

return resumedKeyArr;
}
}

// Assign definition to static attributes
Expand Down
Loading