Skip to content

Commit

Permalink
Added Excel Update & logging (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
arshadparwaiz authored Nov 22, 2024
1 parent eaabf0b commit 1d998b7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
11 changes: 5 additions & 6 deletions actions/graybox/initiate-promote-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ async function main(params) {
projectQueue.push(newProject);
}

logger.info(`In Initiate Preview Worker, Project Queue Json: ${JSON.stringify(projectQueue)}`);
logger.info(`In Initiate Promote Worker, Project Queue Json: ${JSON.stringify(projectQueue)}`);

// Create Project Status JSON
const projectStatusJson = { status: 'initiated', params: inputParams };

logger.info(`In Initiate Preview Worker, projectStatusJson: ${JSON.stringify(projectStatusJson)}`);
logger.info(`In Initiate Promote Worker, projectStatusJson: ${JSON.stringify(projectStatusJson)}`);

// write to JSONs to AIO Files for Projects Queue and Project Status
await filesWrapper.writeFile('graybox_promote/project_queue.json', projectQueue);
Expand All @@ -160,11 +160,11 @@ async function main(params) {

// read Graybox Project Json from AIO Files
const projectQueueJson = await filesWrapper.readFileIntoObject('graybox_promote/project_queue.json');
logger.info(`Project Queue Json: ${JSON.stringify(projectQueueJson)}`);
logger.info(`In Initiate Promote Worker, Project Queue Json: ${JSON.stringify(projectQueueJson)}`);
const statusJson = await filesWrapper.readFileIntoObject(`graybox_promote${gbRootFolder}/${experienceName}/status.json`);
logger.info(`Project Status Json: ${JSON.stringify(statusJson)}`);
logger.info(`In Initiate Promote Worker, Project Status Json: ${JSON.stringify(statusJson)}`);
const projectBatchStatusJson = await filesWrapper.readFileIntoObject(`graybox_promote${gbRootFolder}/${experienceName}/batch_status.json`);
logger.info(`Project Batch Status Json: ${JSON.stringify(projectBatchStatusJson)}`);
logger.info(`In Initiate Promote Worker, Project Batch Status Json: ${JSON.stringify(projectBatchStatusJson)}`);

// process data in batches
let responsePayload;
Expand Down Expand Up @@ -221,7 +221,6 @@ async function findAllGrayboxFiles({
for (let di = 0; di < driveItems?.length; di += 1) {
const item = driveItems[di];
const itemPath = `${item.parentReference.path.replace(pPathRegExp, '')}/${item.name}`;
logger.info(`${itemPath} ::: ${pathsToSelectRegExp.test(itemPath)}`);
if (!isFilePatternMatched(itemPath, promoteIgnoreList)) {
if (item.folder) {
// it is a folder
Expand Down
17 changes: 15 additions & 2 deletions actions/graybox/preview-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ async function main(params) {
if (helixUtils.canBulkPreview(true)) {
logger.info('In Preview Worker, Bulk Previewing Graybox files');
if ((projectStatusJson.status === 'initiated' || projectStatusJson.status === 'promoted')) {
try {
let excelValues = '';
if (projectStatusJson.status === 'initiated') {
excelValues = [['Initial Preview of Graybox completed', toUTCStr(new Date()), `Initial Preview started for '${experienceName}' experience`]];
} else if (projectStatusJson.status === 'promoted') {
excelValues = [['Final Preview of Promoted Content completed', toUTCStr(new Date()), `Final Preview started for promoted content of '${experienceName}' experience`]];
}
// Update Preview Status
await sharepoint.updateExcelTable(projectExcelPath, 'PROMOTE_STATUS', excelValues);
} catch (err) {
logger.error(`Error Occured while updating Excel before starting Graybox Preview: ${err}`);
}
const batchStatusJson = await filesWrapper.readFileIntoObject(`graybox_promote${gbRootFolder}/${experienceName}/batch_status.json`);

logger.info(`In Preview-Worker, batchStatusJson: ${JSON.stringify(batchStatusJson)}`);
Expand Down Expand Up @@ -135,7 +147,7 @@ async function main(params) {
// Update Preview Status
await sharepoint.updateExcelTable(projectExcelPath, 'PROMOTE_STATUS', excelValues);
} catch (err) {
logger.error(`Error Occured while updating Excel during Graybox Initial Preview: ${err}`);
logger.error(`Error Occured while updating Excel during Graybox Preview: ${err}`);
}
}

Expand Down Expand Up @@ -166,9 +178,11 @@ async function main(params) {

const failedPreviewPaths = Object.keys(failedPreviewPathToBatchMap);

logger.info(`Failed paths from First Preview attempt ::: ${failedPreviewPaths}`);
// Re-attempt preview for failed previews
const reAttemptPreviewStatuses = await helixUtils.bulkPreview(failedPreviewPaths, helixUtils.getOperations().PREVIEW, experienceName, isGraybox);

logger.info(`Reattempt Preview Statuses :::: ${JSON.stringify(reAttemptPreviewStatuses)}`);
// Update the previewStatuses object with the re-attempted preview statuses
reAttemptPreviewStatuses.forEach((reattemptedStatus) => {
// Extract the batch name for a specific path
Expand Down Expand Up @@ -230,7 +244,6 @@ async function main(params) {
if (batchJson) {
batchJson.forEach((gbFile) => paths.push(handleExtension(gbFile)));

logger.info(`paths before initial preview :::: ${paths}`);
// Perform Bulk Preview of a Batch of Graybox files
if (isGraybox) {
previewStatuses[batchName] = await helixUtils.bulkPreview(paths, helixUtils.getOperations().PREVIEW, experienceName, isGraybox);
Expand Down

0 comments on commit 1d998b7

Please sign in to comment.