Skip to content

Commit

Permalink
Merge pull request #1630 from Accenture/feature/1434-resume-journey
Browse files Browse the repository at this point in the history
feature/1434 add resume journey via execute-method
  • Loading branch information
JoernBerkefeld authored Sep 2, 2024
2 parents c13c4b1 + b3b96a6 commit e36844c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
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

0 comments on commit e36844c

Please sign in to comment.