diff --git a/lib/cli.js b/lib/cli.js index 4dc54671c..5e4a2ab37 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -679,8 +679,8 @@ yargs(hideBin(process.argv)) } ) .command( - ['execute [TYPE] [KEY]', 'exec', 'start'], - 'executes the entity (query/journey/automation etc.)', + ['execute [TYPE] [KEY]', 'exec', 'start', 'resume'], + 'executes the entity', (yargs) => yargs .positional('BU', { @@ -733,7 +733,7 @@ yargs(hideBin(process.argv)) } ) .command( - ['publish [TYPE] [KEY]'], + ['publish [TYPE] [KEY]', 'activate'], 'publishes the entity', (yargs) => yargs diff --git a/lib/metadataTypes/Journey.js b/lib/metadataTypes/Journey.js index ebc8a0d5b..ec5a9fb86 100644 --- a/lib/metadataTypes/Journey.js +++ b/lib/metadataTypes/Journey.js @@ -2000,6 +2000,50 @@ class Journey extends MetadataType { return stoppedKeyArr; } + /** + * resumes selected journey versions + * + * @param {string[]} keyArr customerkey of the metadata + * @returns {Promise.} 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