Skip to content

Commit

Permalink
MWPW-144478 - Adding Failed Previews written to the Excel (#8)
Browse files Browse the repository at this point in the history
Co-authored-by: armohamm <armohamm@adobe.com>
Co-authored-by: Sunil Kamat <107644736+sukamat@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 2, 2024
1 parent 17425b4 commit 4299940
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
15 changes: 8 additions & 7 deletions actions/graybox/promote-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,27 @@ async function main(params) {

// process data in batches
const previewStatuses = [];

let failedPreviews = '';
if (helixUtils.canBulkPreview()) {
const paths = [];

const paths = [];
batchArray.forEach((batch) => {
batch.forEach((gbFile) => paths.push(handleExtension(gbFile.filePath)));
});

previewStatuses.push(await helixUtils.bulkPreview(paths, helixUtils.getOperations().PREVIEW, experienceName));
const previewStatuses = await helixUtils.bulkPreview(paths, helixUtils.getOperations().PREVIEW, experienceName);

logger.info(`Preview Statuses >> ${JSON.stringify(previewStatuses)}`);
failedPreviews = previewStatuses.filter((status) => !status.success).map((status) => status.path);
const promoteErrors = failedPreviews.length > 0;

const failedPreviews = previewStatuses.filter((status) => !status.success).map((status) => status.path);
logger.info(`Failed Previews: ${JSON.stringify(failedPreviews)}`);
}

// Update project excel file with status (sample)
logger.info('Updating project excel file with status');
const curreDateTime = new Date();
const { projectExcelPath } = appConfig.getPayload();
const excelValues = [['Sample Excel Update', toUTCStr(curreDateTime), 'sukamat@adobe.com', '']];
const sFailedPreviews = failedPreviews.length > 0 ? 'Failed Previews: \n' + failedPreviews.join('\n') : '';
const excelValues = [['Preview', toUTCStr(curreDateTime), sFailedPreviews]];
await updateExcelTable(projectExcelPath, 'PROMOTE_STATUS', excelValues, IS_GRAYBOX);
logger.info('Project excel file updated with promote status.');

Expand Down
18 changes: 10 additions & 8 deletions actions/helixUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ class HelixUtils {
* @returns List of path with preview/pubish status e.g. [{path:'/draft/file1', success: true}..]
*/
async bulkPreview(paths, operation, grayboxExperienceName, retryAttempt = 1) {
let prevPubStatuses = paths.filter((p) => p).map((path) => ({ success: false, path, resourcePath: '' }));
if (!prevPubStatuses.length) {
return prevPubStatuses;
let prevStatuses = paths.filter((p) => p).map((path) => ({ success: false, path, resourcePath: '', responseCode: '' }));
if (!prevStatuses.length) {
return prevStatuses;
}
try {
const repo = this.getRepo();
Expand All @@ -92,7 +92,7 @@ class HelixUtils {
logger.info(`${operation} call response ${response.status} for ${bulkUrl}`);
if (!response.ok && !AUTH_ERRORS.includes(response.status) && retryAttempt <= MAX_RETRIES) {
await delay(RETRY_DELAY * 1000);
prevPubStatuses = await this.bulkPreview(paths, operation, grayboxExperienceName, retryAttempt + 1);
prevStatuses = await this.bulkPreview(paths, operation, grayboxExperienceName, retryAttempt + 1);
} else if (response.ok) {
// Get job details
const jobResp = await response.json();
Expand All @@ -101,22 +101,23 @@ class HelixUtils {
logger.info(`check again jobName : ${jobName} operation : ${operation} repo : ${repo}`);
const jobStatus = await this.bulkJobStatus(jobName, operation, repo);
logger.info(`jobStatus : ${JSON.stringify(jobStatus)}`);
prevPubStatuses.forEach((e) => {
prevStatuses.forEach((e) => {
logger.info(`Job details : ${jobName} / ${jobResp.messageId} / ${jobResp.job?.state}`);
if (jobStatus[e.path]?.success) {
e.success = true;
e.resourcePath = jobStatus[e.path]?.resourcePath;
}
e.responseCode = jobStatus[e.path]?.responseCode;
});
}
}
} catch (error) {
logger.info(`Error in bulk ${operation} status: ${error.message}`);
prevPubStatuses.forEach((e) => {
prevStatuses.forEach((e) => {
e.success = false;
});
}
return prevPubStatuses;
return prevStatuses;
}

/**
Expand Down Expand Up @@ -146,9 +147,10 @@ class HelixUtils {
await this.bulkJobStatus(jobName, operation, repo, bulkPreviewStatus, retryAttempt + 1);
} else if (response.ok) {
const jobStatusJson = await response.json();
logger.info(`jobStatusJson ${JSON.stringify(jobStatusJson)}`);
logger.info(`${operation} progress ${JSON.stringify(jobStatusJson.progress)}`);
jobStatusJson.data?.resources?.forEach((rs) => {
bulkPreviewStatus[rs.path] = { success: JOB_STATUS_CODES.includes(rs.status), resourcePath: rs?.resourcePath };
bulkPreviewStatus[rs.path] = { success: JOB_STATUS_CODES.includes(rs.status), resourcePath: rs?.resourcePath, responseCode: rs.status };
});
if (jobStatusJson.state !== 'stopped' && !jobStatusJson.cancelled &&
retryAttempt <= appConfig.getConfig().maxBulkPreviewChecks) {
Expand Down

0 comments on commit 4299940

Please sign in to comment.