Skip to content

Commit

Permalink
Merge pull request #601 from vlocityinc/alpha
Browse files Browse the repository at this point in the history
Skip LWC Deployment for OS upon any failure
  • Loading branch information
manas-sf authored Jul 16, 2023
2 parents 529e839 + 4425edc commit 385cc65
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 13 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,12 @@ when set to false or ommited, this is the expected output:

![Bindings](doc/deployGeneratedLwcWithSfdxCli.png)

To keep OmniScript activated post deployment and activation, in case of LWC deployment failure, Please add below parameter:

```
keepOSActiveWhenLWCDeploymentFails: true
```

*obs: At the moment, configuring this property only affects OmniScript / FlexCards local compilation step*

# The Job File
Expand Down
30 changes: 27 additions & 3 deletions lib/datapacksjob.js
Original file line number Diff line number Diff line change
Expand Up @@ -2820,9 +2820,33 @@ DataPacksJob.prototype.deployJob = async function(jobInfo) {
);
}
} catch (err) {
VlocityUtils.log(err);
jobInfo.errors.push( "Exception while deploying compiled LWC components:\n" + JSON.stringify(err, null, 2));
jobInfo.hasError = true;
if (jobInfo.keepOSActiveWhenLWCDeploymentFails) {
if (err.result && err.result.details && err.result.details.componentSuccesses) {
err.result.details.componentSuccesses
.forEach((metadata) => {
if (metadata.componentType) {
var metadataKey = `${metadata.componentType}/${metadata.fullName}`;
VlocityUtils.success('Metadata Deployed', metadataKey);
jobInfo.currentStatus[metadataKey] = 'Success';
}
}
);
err.result.details.componentFailures
.forEach((metadata) => {
if (metadata.componentType) {
var metadataKey = `${metadata.componentType}/${metadata.fullName}`;
VlocityUtils.error('Metadata Deployment Failed - ' + metadata.problem, metadataKey);
jobInfo.currentStatus[metadataKey] = 'Failure';
}
}
);
}
VlocityUtils.log('Skipping Deactivation of OmniScript as keepOSActiveWhenLWCDeploymentFails = true. As per this param, Deployed OmniScripts will remain active irrespective of LWC is deployed or not.');
} else {
VlocityUtils.log(err);
jobInfo.errors.push("Exception while deploying compiled LWC components:\n" + JSON.stringify(err, null, 2));
jobInfo.hasError = true;
}
}
}
}
Expand Down
20 changes: 12 additions & 8 deletions lib/datapacktypes/omniscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,23 @@ OmniScript.prototype.createTitleObjects = function (input) {
return titleObjects;
};

OmniScript.prototype.deactivateOmniScript = async function (omniscriptID) {
OmniScript.prototype.deactivateOmniScript = async function (omniscriptID, jobInfo) {
const osAPIName = this.vlocity.namespace + '__OmniScript__c';
const osAPIActiveFieldName = this.vlocity.namespace + '__IsActive__c';
var toUpdate = {};
toUpdate[osAPIActiveFieldName] = false;
toUpdate.Id = omniscriptID;
try {
var result = await this.vlocity.jsForceConnection.sobject(osAPIName).update(toUpdate);
if (!result.success) {
VlocityUtils.error('Deactivating OmniScript ', 'Id: ' + omniscriptID + ' Unable to deactivate OmniScript. OmniScript is still activated.');
}
else {
VlocityUtils.log('Deactivating OmniScript ', omniscriptID, 'OmniScript was deactivated');
if (jobInfo && jobInfo.keepOSActiveWhenLWCDeploymentFails) {
VlocityUtils.log('Skipping Deactivation of OmniScript - ' + omniscriptID + ' as keepOSActiveWhenLWCDeploymentFails = true. As per this param, Deployed OmniScript will remain active irrespective of LWC is deployed or not.');
} else {
var result = await this.vlocity.jsForceConnection.sobject(osAPIName).update(toUpdate);
if (!result.success) {
VlocityUtils.error('Deactivating OmniScript ', 'Id: ' + omniscriptID + ' Unable to deactivate OmniScript. OmniScript is still activated.');
}
else {
VlocityUtils.log('Deactivating OmniScript ', omniscriptID, 'OmniScript was deactivated');
}
}
} catch (error) {
VlocityUtils.error('Deactivating OmniScript ', 'Id: ' + omniscriptID + ' Unable to deactivate OmniScript. OmniScript is still activated - ' + error);
Expand Down Expand Up @@ -402,7 +406,7 @@ OmniScript.prototype.compileOSLWC = async function (jobInfo, omniScriptId, omniS
jobInfo.currentErrors[omniScriptKey] = 'LWC Activation Error >> ' + omniScriptKey + ' - ' + e;
jobInfo.errors.push('LWC Activation Error >> ' + omniScriptKey + ' - ' + e);
VlocityUtils.error('LWC Activation Error', omniScriptKey + ' - ' + e);
await this.deactivateOmniScript(omniScriptId);
await this.deactivateOmniScript(omniScriptId, jobInfo);

try {
browser.close();
Expand Down
3 changes: 2 additions & 1 deletion lib/vlocitycli.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ var VLOCITY_COMMANDLINE_OPTIONS = {
"ignoreLWCActivationCards": Boolean,
"ignoreLocalCompilationCards": Boolean,
"puppeteerHttpProxy": String,
"overrideOrgCommit": String
"overrideOrgCommit": String,
"keepOSActiveWhenLWCDeploymentFails": Boolean
};

var VLOCITY_COMMANDLINE_OPTIONS_SHORTHAND = {
Expand Down
2 changes: 1 addition & 1 deletion lib/vlocityutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ VlocityUtils.loadCompiler = async function (nameOfCompiler, jobInfo, packageVers
return await VlocityUtils.requirePlugin(jobInfo, lwcCompiler, lwcCompilerVersion);
} catch (err) {
VlocityUtils.log(`Can also install compiler with npm install ${lwcCompiler}`);
VlocityUtils.error('An error occurred while loading OmniScript compiler: ' + err + ' - If you are using Puppeteer for LWC compilation this error can be ignored');
VlocityUtils.log('An error occurred while loading OmniScript compiler: ' + err + ' - If you are using Puppeteer for LWC compilation this error can be ignored');
return null;
}
}

0 comments on commit 385cc65

Please sign in to comment.