-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MWPW-144264 Unpublish content when delete action is run on the floodg…
…ate (#105) ### On Delete: Unpublish Content 1. Retrieve the files to unpublish using the Helix status URLs. 2. Batch unpublish the files. 3. After unpublishing, delete the folder. ### Configuration Keys Added: - `DELETE_ROOT_PATH=/drafts/raga/tmp/` - `MAX_DELETE_FILES_PER_BATCH=350` > Set `DELETE_ROOT_PATH` to empty once live and adjust `MAX_DELETE_FILES_PER_BATCH` as needed for batching. ### State Keys Change (use `stateStore` to fetch) **Example:** - `copyAction:/adobecom/CC/www-pink:/drafts/floodgate/projects/raga/samplefgprojectone.xlsx` - `promoteAction:/adobecom/CC/www-pink` - `deleteAction:/adobecom/CC/www-pink` ## TESTING **Before delete** ![image](https://github.com/user-attachments/assets/0cd3c581-92ca-4c45-b355-9eb0e697b910) **After Delete** ![image](https://github.com/user-attachments/assets/b5ea9124-ba0e-4ce4-a2be-227622370db2) **Maintenance Tracker Changes** ![image](https://github.com/user-attachments/assets/1800fddb-c2d5-4219-94e1-0b8a2b26e647)
- Loading branch information
Showing
19 changed files
with
510 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* eslint-disable no-await-in-loop */ | ||
/* ************************************************************************ | ||
* ADOBE CONFIDENTIAL | ||
* ___________________ | ||
* | ||
* Copyright 2023 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. | ||
************************************************************************* */ | ||
const openwhisk = require('openwhisk'); | ||
const Sharepoint = require('../sharepoint'); | ||
const { | ||
successResponse, getAioLogger, DELETE_ACTION, | ||
} = require('../utils'); | ||
const AppConfig = require('../appConfig'); | ||
const FgStatus = require('../fgStatus'); | ||
const BatchManager = require('../batchManager'); | ||
const FgAction = require('../fgAction'); | ||
const FgDeleteActionHelper = require('../fgDeleteActionHelper'); | ||
|
||
const logger = getAioLogger(); | ||
|
||
async function main(params) { | ||
let respPayload; | ||
|
||
const valParams = { | ||
statParams: ['fgRootFolder'], | ||
actParams: ['adminPageUri', 'projectExcelPath'], | ||
checkUser: false, | ||
checkStatus: false, | ||
checkActivation: false, | ||
}; | ||
|
||
const ow = openwhisk(); | ||
let appConfig = new AppConfig(params); | ||
const fgDeleteActionHelper = new FgDeleteActionHelper(); | ||
const batchManager = new BatchManager({ | ||
key: DELETE_ACTION, | ||
batchConfig: appConfig.getDeleteBatchConfig(), | ||
}); | ||
|
||
await batchManager.init(); | ||
|
||
if (await batchManager.isInstanceRunning()) { | ||
return successResponse('Skipping, Instance is running!'); | ||
} | ||
|
||
// Read instance_info.json | ||
const instanceContent = await batchManager.getInstanceData(); | ||
if (!instanceContent?.dtls) { | ||
return successResponse('None to run!'); | ||
} | ||
|
||
const { batchesInfo } = instanceContent.dtls; | ||
|
||
// Initialize action | ||
appConfig = new AppConfig({ ...params, ...instanceContent.dtls }); | ||
const fgAction = new FgAction(DELETE_ACTION, appConfig); | ||
fgAction.init({ ow, skipUserDetails: true }); | ||
const { fgStatus } = fgAction.getActionParams(); | ||
|
||
try { | ||
await batchManager.markInstanceRunning(); | ||
const vStat = await fgAction.validateAction(valParams); | ||
if (vStat && vStat.code !== 200) { | ||
return vStat; | ||
} | ||
|
||
const { payload } = appConfig.getConfig(); | ||
|
||
// Find the batch to be triggered | ||
const total = batchesInfo.length; | ||
const nextBatch = batchesInfo.find((b) => !b.done); | ||
const batchNumber = nextBatch?.batchNumber; | ||
|
||
if (!batchNumber) { | ||
await fgStatus.updateStatusToStateLib({ status: FgStatus.PROJECT_STATUS.COMPLETED }); | ||
return successResponse('None to be processed!'); | ||
} | ||
|
||
respPayload = `Unpublishing batch ${batchNumber} / ${total}`; | ||
await fgStatus.updateStatusToStateLib({ | ||
status: FgStatus.PROJECT_STATUS.IN_PROGRESS, | ||
statusMessage: respPayload, | ||
}); | ||
|
||
logger.info(respPayload); | ||
await fgDeleteActionHelper.processBatch(appConfig, batchManager, nextBatch); | ||
await batchManager.writeToInstanceFile(instanceContent); | ||
|
||
// Complete the process when all batches are completed | ||
const hasPendingBatches = batchesInfo.find((b) => !b.done); | ||
logger.info(`Has pending batches: ${hasPendingBatches}`); | ||
|
||
if (!hasPendingBatches) { | ||
const sharepoint = new Sharepoint(appConfig); | ||
await fgDeleteActionHelper.completeProcess(payload.projectExcelPath, batchManager, batchesInfo, fgStatus, sharepoint); | ||
respPayload = 'Delete process completed.'; | ||
} | ||
|
||
logger.info(respPayload); | ||
respPayload = 'Delete trigger and track completed.'; | ||
} catch (err) { | ||
logger.error(err); | ||
respPayload = err; | ||
|
||
// In case of error, log status with end time | ||
try { | ||
await fgStatus.updateStatusToStateLib({ | ||
status: FgStatus.PROJECT_STATUS.COMPLETED_WITH_ERROR, | ||
statusMessage: err.message, | ||
}); | ||
} catch (err2) { | ||
logger.info('Error while updating failed status'); | ||
} | ||
} | ||
|
||
await batchManager.markInstancePaused(); | ||
return { | ||
body: respPayload, | ||
}; | ||
} | ||
|
||
exports.main = main; |
Oops, something went wrong.