From 3507a1b76732bee0fa98b809494f8c2faac38d2a Mon Sep 17 00:00:00 2001 From: Arshad Mohammed <87503056+arshadparwaiz@users.noreply.github.com> Date: Tue, 17 Dec 2024 09:34:17 -0800 Subject: [PATCH] MWPW-164197 - Clear the Blocked Queue by Pausing a Project (#39) (#42) --- actions/graybox/pause-project-in-queue.js | 81 +++++++++++++++++++++++ app.config.yaml | 6 ++ 2 files changed, 87 insertions(+) create mode 100644 actions/graybox/pause-project-in-queue.js diff --git a/actions/graybox/pause-project-in-queue.js b/actions/graybox/pause-project-in-queue.js new file mode 100644 index 0000000..3147556 --- /dev/null +++ b/actions/graybox/pause-project-in-queue.js @@ -0,0 +1,81 @@ +/* ************************************************************************ +* ADOBE CONFIDENTIAL +* ___________________ +* +* Copyright 2024 Adobe +* All Rights Reserved. +* +* NOTICE: All information contained herein is, and remains +* the property of Adobe and its suppliers, if any. The intellectual +* and technical concepts contained herein are proprietary to Adobe +* and its suppliers and are protected by all applicable intellectual +* property laws, including trade secret and copyright laws. +* Dissemination of this information or reproduction of this material +* is strictly forbidden unless prior written permission is obtained +* from Adobe. +************************************************************************* */ + +// eslint-disable-next-line import/no-extraneous-dependencies +const initFilesWrapper = require('./filesWrapper'); +const { getAioLogger } = require('../utils'); +/** + * This Action Sets the project status to paused in Project Queue & the Project Status JSON of that project + */ +async function main(params) { + const logger = getAioLogger(); + const filesWrapper = await initFilesWrapper(logger); + let responsePayload = 'Graybox Pause Project in Project Queue action invoked'; + let responseCode = 200; + logger.info(responsePayload); + try { + const { projectPath } = params; + logger.info(`Project to be paused :: ${projectPath}`); + const projectQueuePath = 'graybox_promote/project_queue.json'; + if (await filesWrapper.fileExists(projectQueuePath)) { + const projectQueue = await filesWrapper.readFileIntoObject(projectQueuePath); + if (projectQueue) { + const index = projectQueue.findIndex((obj) => obj.projectPath === projectPath); + if (!index) { + responsePayload = `No project with ${projectPath} path exists in the project queue`; + return { + code: responseCode, + payload: responsePayload, + }; + } + logger.info(`In Pause Project Action, Before pausing, Project Queue Json: ${JSON.stringify(projectQueue)}`); + projectQueue[index].status = 'paused'; + await filesWrapper.writeFile(projectQueuePath, projectQueue); + const project = projectQueue[index].projectPath; + logger.info(`In Pause Project Action, After pausing, Project Queue Json: ${JSON.stringify(projectQueue)}`); + const projectStatusJson = await filesWrapper.readFileIntoObject(`graybox_promote${project}/status.json`); + logger.info(`In Pause Graybox Project, Before Pausing Project Status Json: ${JSON.stringify(projectStatusJson)}`); + projectStatusJson.status = 'paused'; + await filesWrapper.writeFile(`graybox_promote${project}/status.json`, projectStatusJson); + } else { + responsePayload = `Project Queue empty. No project with ${projectPath} path exists`; + return { + code: responseCode, + payload: responsePayload, + }; + } + } else { + responsePayload = 'Project Queue file doesn\'t exist in AIO'; + return { + code: responseCode, + payload: responsePayload, + }; + } + } catch (err) { + responsePayload = 'Unknown error occurred'; + logger.error(`${responsePayload}: ${err}`); + responsePayload = err; + responseCode = 500; + } + + return { + code: responseCode, + payload: responsePayload, + }; +} + +exports.main = main; diff --git a/app.config.yaml b/app.config.yaml index a669588..f427032 100644 --- a/app.config.yaml +++ b/app.config.yaml @@ -71,6 +71,12 @@ application: limits: timeout: 3600000 memorySize: 2048 + pause-project-in-queue: + function: actions/graybox/pause-project-in-queue.js + web: 'yes' + runtime: nodejs:18 + inputs: + LOG_LEVEL: debug preview-sched: function: actions/graybox/preview-sched.js web: 'no'