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

Bug/1803 deploy publish does not update local event jsons after success #1977

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
5 changes: 4 additions & 1 deletion @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.

125 changes: 81 additions & 44 deletions lib/metadataTypes/Journey.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import yoctoSpinner from 'yocto-spinner';
* @typedef {import('../../types/mcdev.d.js').MetadataTypeMapObj} MetadataTypeMapObj
* @typedef {import('../../types/mcdev.d.js').SoapRequestParams} SoapRequestParams
* @typedef {import('../../types/mcdev.d.js').TemplateMap} TemplateMap
* @typedef {import('../../types/mcdev.d.js').TypeKeyCombo} TypeKeyCombo
*/

/**
Expand Down Expand Up @@ -1863,7 +1864,7 @@ class Journey extends MetadataType {
const idArr = Object.values(upsertResults).map(
(item) => 'id:' + item.id + '/' + item.version
);
await this.publish(idArr);
await this.publish(idArr, upsertResults);
} else if (Util.OPTIONS.validate) {
Util.logger.info(`Validating: ${this.definition.type}`);
// pubslih
Expand All @@ -1883,15 +1884,18 @@ class Journey extends MetadataType {
* a function to publish the journey via API
*
* @param {string[]} keyArr keys or ids of the metadata
* @param {MetadataTypeMap} [upsertResults] metadata mapped by their keyField as returned by update/create
* @returns {Promise.<string[]>} Returns list of updated keys/ids that were published. Success could only be seen with a delay in the UI because the publish-endpoint is async
*/
static async publish(keyArr) {
static async publish(keyArr, upsertResults) {
const resultsTransactional = [];
// works only with objectId
const statusUrls = [];
const executedKeyArr = [];
const refreshTransactionalKeys = [];
const metadataMap = await this.retrieveForCache();
const metadataMap = upsertResults
? { metadata: upsertResults }
: await this.retrieveForCache();
const spinnerTransactional = yoctoSpinner({
text: `Publishing transactional journey…`,
});
Expand Down Expand Up @@ -1994,7 +1998,7 @@ class Journey extends MetadataType {
statusUrls.push({ key, statusUrl: response.statusUrl });
}
spinnerTransactional.start();
return key;
return journey[this.definition.keyField];
} catch (ex) {
spinnerTransactional.stop();
if (
Expand Down Expand Up @@ -2043,6 +2047,11 @@ class Journey extends MetadataType {
} else {
throw new Error(response);
}
if (Util.OPTIONS.skipStatusCheck) {
Util.logger.warn(
` - Skipping status check for publishing journey ${key} due to --skipStatusCheck flag`
);
}
if (!Util.OPTIONS.skipStatusCheck && statusUrl) {
const spinner = yoctoSpinner({
text: `Publishing journey…`,
Expand Down Expand Up @@ -2101,6 +2110,10 @@ class Journey extends MetadataType {
}
} // for loop

const publishedJourneyCounter = {
multiStep: executedKeyArr.filter(Boolean).length,
transactional: 0,
};
// Transactional Send Journeys
if (resultsTransactional.length) {
const transactionalKeyArr = (await Promise.all(resultsTransactional)).filter(Boolean);
Expand All @@ -2109,55 +2122,79 @@ class Journey extends MetadataType {
// if all publish actions failed, we don't need to re-retrieve anything here
if (transactionalKeyArr.length) {
executedKeyArr.push(...transactionalKeyArr);

publishedJourneyCounter.transactional = transactionalKeyArr.length;
// reset transactionalEmail cache to trigger re-caching it.
cache.clearCache(this.buObject.mid, 'transactionalEmail');
}
}

Util.logger.info('Retrieving relevant journeys');
const retriever = new Retriever(this.properties, this.buObject);

try {
const updatedJourneyRetrieve = await retriever.retrieve(
['journey'],
transactionalKeyArr
);
// reload published non-transactional journeys including their events
if (executedKeyArr.filter(Boolean).length) {
Util.logger.info('Re-retrieving published journeys');
const retriever = new Retriever(this.properties, this.buObject);
try {
// we need to retrieve the updated journeys and all dependencies
const updatedJourneyRetrieve = await retriever.retrieve(
['journey'],
executedKeyArr.filter(Boolean)
);

/** @type {MetadataTypeItem[]} */
const updatedJourneys =
updatedJourneyRetrieve?.journey?.length > 1
? Object.values(
updatedJourneyRetrieve?.journey.reduce(
(previousValue, currentValue) =>
Object.assign(previousValue, currentValue),
{}
)
/** @type {MetadataTypeItem[]} */
const updatedJourneys =
updatedJourneyRetrieve?.journey?.length > 1
? Object.values(
updatedJourneyRetrieve?.journey.reduce(
(previousValue, currentValue) =>
Object.assign(previousValue, currentValue),
{}
)
: Object.values(updatedJourneyRetrieve?.journey[0]);
if (updatedJourneys) {
const updatedTransactionalEmails = [];
for (const journey of updatedJourneys) {
updatedTransactionalEmails.push(
journey.activities?.[0]?.configurationArguments
?.r__transactionalEmail_key
);
}
if (updatedTransactionalEmails.filter(Boolean).length) {
Util.logger.info('Retrieving relevant transactionalEmails');
await retriever.retrieve(
['transactionalEmail'],
updatedTransactionalEmails.filter(Boolean)
);
} else {
Util.logger.error(
`Could not find transactional Emails for the published journeys`
);
}
)
: Object.values(updatedJourneyRetrieve?.journey[0]);

if (updatedJourneys) {
// regardless of upsert vs publish-only mode, we need to retrieve the events/transactionalEmail and their dependencies
const updatedEvents = [];
const updatedTransactionalEmails = [];
for (const journey of updatedJourneys) {
// multi-step journeys
updatedEvents.push(journey.triggers?.[0]?.metaData?.r__event_key);
// transactional-send journeys
updatedTransactionalEmails.push(
journey.activities?.[0]?.configurationArguments
?.r__transactionalEmail_key
);
}
/** @type {TypeKeyCombo} */
const eventTransEmailCombo = {};
if (updatedEvents.filter(Boolean).length) {
eventTransEmailCombo.event = updatedEvents.filter(Boolean);
} else if (publishedJourneyCounter.multiStep) {
Util.logger.error(`Could not find events for the published journeys`);
}
if (updatedTransactionalEmails.filter(Boolean).length) {
eventTransEmailCombo.transactionalEmail =
updatedTransactionalEmails.filter(Boolean);
Util.logger.info('Retrieving relevant transactionalEmails');
} else if (publishedJourneyCounter.transactional) {
Util.logger.error(
`Could not find transactional Emails for the published journeys`
);
}

const toBeRetrievedTypes = Object.keys(eventTransEmailCombo);
if (toBeRetrievedTypes.length) {
Util.logger.info(
'Retrieving relevant ' +
toBeRetrievedTypes.map((item) => item + 's').join(', ')
);
await retriever.retrieve(toBeRetrievedTypes, eventTransEmailCombo);
}
} catch (ex) {
Util.logger.errorStack(ex, 'retrieve failed');
}
} catch (ex) {
Util.logger.errorStack(ex, 'retrieve failed');
}
}

Util.logger.info(
`Published ${executedKeyArr.filter(Boolean).length} of ${keyArr.length} items`
);
Expand Down
Loading
Loading