Skip to content

Commit

Permalink
#1923: allow publish OR validate flag when deploying journeys; also a…
Browse files Browse the repository at this point in the history
…lways require re-caching for refresh
  • Loading branch information
JoernBerkefeld committed Jan 9, 2025
1 parent 737ae48 commit 41721bc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
3 changes: 1 addition & 2 deletions @types/lib/metadataTypes/Journey.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.

38 changes: 23 additions & 15 deletions lib/metadataTypes/Journey.js
Original file line number Diff line number Diff line change
Expand Up @@ -1834,15 +1834,27 @@ class Journey extends MetadataType {
* @param {MetadataTypeMap} upsertResults metadata mapped by their keyField as returned by update/create
*/
static async postDeployTasks(upsertResults) {
let postDeployFlags = 0;
if (Util.OPTIONS.publish) {
postDeployFlags++;
}
if (Util.OPTIONS.validate) {
postDeployFlags++;
}
if (postDeployFlags > 1) {
Util.logger.warn(
`Please provide only one of the following options (--publish, --validate, --refresh). Flags are processed in this order and only the first one found is executed.`
);
}

if (Util.OPTIONS.publish) {
Util.logger.info(`Publishing: ${this.definition.type}`);
// pubslih
const idArr = Object.values(upsertResults).map(
(item) => 'id:' + item.id + '/' + item.version
);
await this.publish(idArr);
}
if (Util.OPTIONS.validate) {
} else if (Util.OPTIONS.validate) {
Util.logger.info(`Validating: ${this.definition.type}`);
// pubslih
const idArr = Object.values(upsertResults).map(
Expand Down Expand Up @@ -2675,21 +2687,17 @@ class Journey extends MetadataType {
* TSD-specific refresh method that finds active TSDs and refreshes them
*
* @param {string[]} keyArr metadata keys
* @param {boolean} [checkKey] whether to check if the key is valid
* @returns {Promise.<string[]>} Returns list of keys that were refreshed
*/
static async refresh(keyArr, checkKey = true) {
static async refresh(keyArr) {
console.time('Time'); // eslint-disable-line no-console
if (!keyArr) {
if (!Array.isArray(keyArr) || !keyArr.length) {
Util.logger.error('No refresh-keys provided');
return [];
// keyArr = await this.getKeysForValidTSDs((await this.findRefreshableItems()).metadata);
// checkKey = false;
}
let journeyCache;
if (checkKey) {
journeyCache = await this.retrieveForCache();
}
const journeyCache = await this.retrieveForCache();
// then executes pause, publish, start on them.
Util.logger.info(`Refreshing ${keyArr.length} ${this.definition.typeName}...`);
Util.logger.debug(`Refreshing keys: ${keyArr.join(', ')}`);
Expand All @@ -2699,23 +2707,23 @@ class Journey extends MetadataType {
await Promise.all(
keyArr.map((key) =>
rateLimit(async () => {
if (checkKey && !journeyCache.metadata[key]) {
if (!journeyCache.metadata[key]) {
Util.logger.error(
` ☇ skipping refresh of ${this.definition.type} ${key}: not found on server`
);
return;
}
switch (journeyCache.metadata[key].definitionType) {
case 'Transactional': {
if (checkKey && journeyCache.metadata[key]?.status !== 'Published') {
Util.logger.error(
` ☇ skipping refresh of ${this.definition.type} ${key}: Can only refresh journeys with status 'Published'. Found status: ${journeyCache.metadata[key]?.status}`
);
} else {
if (journeyCache.metadata[key]?.status === 'Published') {
const result = await this._refreshItem(key, journeyCache);
if (result) {
refreshedKeyArr.push(key);
}
} else {
Util.logger.error(
` ☇ skipping refresh of ${this.definition.type} ${key}: Can only refresh journeys with status 'Published'. Found status: ${journeyCache.metadata[key]?.status}`
);
}
break;
}
Expand Down

0 comments on commit 41721bc

Please sign in to comment.