From 42999402c2f71143a27412e1eaa082e33c264e84 Mon Sep 17 00:00:00 2001 From: Arshad Mohammed <87503056+arshadparwaiz@users.noreply.github.com> Date: Tue, 2 Apr 2024 13:33:11 -0700 Subject: [PATCH] MWPW-144478 - Adding Failed Previews written to the Excel (#8) Co-authored-by: armohamm Co-authored-by: Sunil Kamat <107644736+sukamat@users.noreply.github.com> --- actions/graybox/promote-worker.js | 15 ++++++++------- actions/helixUtils.js | 18 ++++++++++-------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/actions/graybox/promote-worker.js b/actions/graybox/promote-worker.js index 676fdba..28bf495 100644 --- a/actions/graybox/promote-worker.js +++ b/actions/graybox/promote-worker.js @@ -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.'); diff --git a/actions/helixUtils.js b/actions/helixUtils.js index f5c1006..9043658 100644 --- a/actions/helixUtils.js +++ b/actions/helixUtils.js @@ -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(); @@ -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(); @@ -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; } /** @@ -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) {