Skip to content

Commit 249465e

Browse files
committed
Add log files. Update tests. Try to better handle session connection issues. Simplify how ant works.
1 parent d8934e2 commit 249465e

34 files changed

+536
-93
lines changed

bin/run-grunt

Lines changed: 0 additions & 15 deletions
This file was deleted.

build.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@
133133
<runDataPackJob packCommand="packDeploy" job="${vlocity.dataPackJob}" />
134134
</target>
135135

136+
<target name="runTestJob" description="">
137+
<runDataPackJob packCommand="runTestJob" job="TestJob" />
138+
</target>
139+
136140
<macrodef name="runDataPackJob" >
137141
<attribute name="packCommand" />
138142
<attribute name="job" />
@@ -142,7 +146,11 @@
142146
<echo> ------------------------------------------- </echo>
143147
<echo> ------------------------------------------- </echo>
144148
<echo> Running - @{packCommand} - @{job}</echo>
145-
<exec executable="${basedir}/bin/run-grunt" dir="${basedir}">
149+
<exec executable="npm" dir="${basedir}">
150+
<arg value="install" />
151+
</exec>
152+
<exec executable="node" dir="${basedir}">
153+
<arg value="./node_modules/grunt-cli/bin/grunt" />
146154
<arg value="@{packCommand}"/>
147155
<arg value="-job"/>
148156
<arg value="@{job}"/>

dataPacksJobs/TestJob.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ expansionPath: testJobRunning
33
buildFile: testJobRunning/testBuildFile.resource
44
queries:
55
- VlocityDataPackType: VlocityUITemplate
6-
query: Select Id from %vlocity_namespace%__VlocityUITemplate__c where Name LIKE 'testpack-%' AND %vlocity_namespace%__Active__c = true
6+
query: Select Id from %vlocity_namespace%__VlocityUITemplate__c where Name LIKE 'datapacktest-%' AND %vlocity_namespace%__Active__c = true
7+
- VlocityDataPackType: VlocityUILayout
8+
query: Select Id from %vlocity_namespace%__VlocityUILayout__c where Name LIKE 'datapacktest-%'
79
delete: true
810
activate: true
911
compileOnBuild: true
1012
preJobApex:
1113
Deploy: TestJob.cls
1214
preStepApex:
13-
Deploy: TestJob.cls
15+
Deploy: DeactivateTemplatesAndLayouts.cls
1416
postStepApex:
1517
Deploy: TestJob.cls
1618
postJobApex:

grunt/dataPacksJobTask.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,14 @@ module.exports = function (grunt) {
286286
fs.removeSync('./test/testJobRunning');
287287
fs.copySync('./test/testJobData', './test/testJobRunning');
288288

289-
var commands = ['Deploy',
290-
'GetDiffs',
291-
'Export',
292-
'GetDiffsAndDeploy',
293-
'BuildFile',
294-
'JavaScript' ];
289+
var commands = [
290+
'Deploy',
291+
'GetDiffs',
292+
'Export',
293+
'GetDiffsAndDeploy',
294+
'BuildFile',
295+
'JavaScript'
296+
];
295297

296298
if (grunt.option('test')) {
297299
commands = [ grunt.option('test') ];

node_vlocity/datapacks.js

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,32 @@ DataPacks.prototype.runDataPackProcess = function(dataPackData, options, onSucce
176176
self.vlocity.checkLogin(function() {
177177
self.vlocity.jsForceConnection.apex.post(self.dataPacksEndpoint, dataPackData, function(err, result) {
178178

179-
if (typeof result == "string") {
180-
result = JSON.parse(result);
181-
}
179+
if (err) {
180+
if (dataPackData.isRetry) {
181+
console.error('\x1b[31m', 'ERROR >>' ,'\x1b[0m', dataPackId, err);
182+
183+
if (onError) onError(err);
184+
else if (onSuccess) onSuccess(err);
185+
else throw err;
186+
} else {
187+
console.error('\x1b[31m', 'RETRYING FOR ERROR >>' ,'\x1b[0m', dataPackId, err);
188+
189+
self.vlocity.isLoggedIn = false;
190+
dataPackData.isRetry = true;
191+
192+
setTimeout(function() { self.runDataPackProcess(dataPackData, options, onSuccess, onError); }, 1000);
193+
}
194+
} else {
195+
dataPackData.isRetry = false;
182196

183-
if (self.vlocity.verbose) {
184-
console.log('Result', result);
185-
}
197+
if (typeof result == "string") {
198+
result = JSON.parse(result);
199+
}
200+
201+
if (self.vlocity.verbose) {
202+
console.log('Result', result);
203+
}
186204

187-
if (result) {
188205
if (result.Total > 0) {
189206
if (dataPackData.processType == "Export"
190207
&& dataPackData.processData
@@ -205,29 +222,26 @@ DataPacks.prototype.runDataPackProcess = function(dataPackData, options, onSucce
205222
console.log('\x1b[32m', 'Activated >>', '\x1b[0m', activatedEntity.VlocityDataPackKey);
206223
});
207224
}
208-
}
209-
210-
if (err) {
211-
console.error('\x1b[31m', 'ERROR >>' ,'\x1b[0m', dataPackId, err);
212-
213-
// Need to hook this in an interesting way
214-
var packError = { VlocityDataPackId: dataPackId, AllErrorMessage: err };
215-
216-
if (onError) onError(err);
217-
else if (onSuccess) onSuccess(err);
218-
else throw err;
219-
} else if (/(Ready|InProgress)/.test(result.Status)) {
220-
dataPackData.processData = result;
221-
222-
setTimeout(function() { self.runDataPackProcess(dataPackData, options, onSuccess, onError); }, result.Async ? 3000 : 1);
223-
} else if (/(Complete|Deleted)/.test(result.Status)) {
224-
225-
if (onSuccess) onSuccess(result);
226-
else console.log(result);
227-
} else if (/Error/.test(result.Status)) {
228-
if (onError) onError(result);
229-
else if (onSuccess) onSuccess(result);
230-
else console.log(result);
225+
226+
if (result.activationError) {
227+
result.activationError.forEach(function(activatedEntity) {
228+
console.log('\x1b[31m', 'Activation Error >>', '\x1b[0m', activatedEntity.VlocityDataPackKey, '---', activatedEntity.ActivationMessage);
229+
});
230+
}
231+
232+
if (/(Ready|InProgress)/.test(result.Status)) {
233+
dataPackData.processData = result;
234+
235+
setTimeout(function() { self.runDataPackProcess(dataPackData, options, onSuccess, onError); }, result.Async ? 3000 : 1);
236+
} else if (/(Complete|Deleted)/.test(result.Status)) {
237+
238+
if (onSuccess) onSuccess(result);
239+
else console.log(result);
240+
} else if (/Error/.test(result.Status)) {
241+
if (onError) onError(result);
242+
else if (onSuccess) onSuccess(result);
243+
else console.log(result);
244+
}
231245
}
232246
});
233247
});

node_vlocity/datapacksbuilder.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,10 @@ DataPacksBuilder.prototype.initializeImportStatus = function(importPath, manifes
322322
jobInfo.currentStatus[generatedDataPackKey] = 'Ready';
323323
}
324324

325+
if (sobjectData.Name) {
326+
jobInfo.generatedKeysToNames[generatedDataPackKey] = sobjectData.Name;
327+
}
328+
325329
if (jobInfo.allParents.indexOf(generatedDataPackKey) == -1) {
326330
jobInfo.allParents.push(generatedDataPackKey);
327331
}

node_vlocity/datapacksexpand.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,10 @@ DataPacksExpand.prototype.preprocessDataPack = function(currentData, jobInfo) {
468468

469469
jobInfo.vlocityKeysToNewNamesMap[currentData.VlocityDataPackKey] = generatedKey;
470470

471+
if (currentData.Name) {
472+
jobInfo.generatedKeysToNames[generatedKey] = currentData.Name;
473+
}
474+
471475
// make sure we don't overwrite keys later
472476
jobInfo.vlocityKeysToNewNamesMap[generatedKey] = generatedKey;
473477

node_vlocity/datapacksjob.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ DataPacksJob.prototype.runJob = function(jobData, jobName, action, onSuccess, on
6969
DataPacksJob.prototype.runJobWithInfo = function(jobInfo, action, onSuccess, onError) {
7070
var self = this;
7171

72-
if (!jobInfo.startTime) {
73-
jobInfo.startTime = Date.now();
74-
}
75-
7672
// Will not continue a single DataPack, but will continue when there are breaks in the job
7773
if (action == 'Continue' || action == 'Retry') {
7874
Object.assign(jobInfo, JSON.parse(fs.readFileSync(CURRENT_INFO_FILE, 'utf8')));
@@ -134,6 +130,14 @@ DataPacksJob.prototype.runJobWithInfo = function(jobInfo, action, onSuccess, onE
134130
action = jobInfo.jobAction;
135131
}
136132

133+
if (jobInfo.startTime == null) {
134+
jobInfo.startTime = Date.now();
135+
}
136+
137+
if (!jobInfo.logName) {
138+
jobInfo.logName = self.vlocity.datapacksexpand.generateFolderOrFilename(jobInfo.jobName + '-' + new Date(Date.now()).toISOString() + '-' + jobInfo.jobAction, 'yaml');
139+
}
140+
137141
// Initialize all that need it
138142
if (jobInfo.extendedManifest == null) {
139143
jobInfo.extendedManifest = {};
@@ -167,9 +171,6 @@ DataPacksJob.prototype.runJobWithInfo = function(jobInfo, action, onSuccess, onE
167171
jobInfo.vlocityRecordSourceKeyMap = {};
168172
}
169173

170-
if (jobInfo.startTime == null) {
171-
jobInfo.startTime = Date.now();
172-
}
173174

174175
if (!jobInfo.addedToExportBuildFile) {
175176
jobInfo.addedToExportBuildFile = [];
@@ -184,6 +185,10 @@ DataPacksJob.prototype.runJobWithInfo = function(jobInfo, action, onSuccess, onE
184185
jobInfo.VlocityDataPackIds = {};
185186
}
186187

188+
if (!jobInfo.generatedKeysToNames) {
189+
jobInfo.generatedKeysToNames = {};
190+
}
191+
187192
jobInfo.supportParallel = jobInfo.defaultMaxParallel > 1;
188193

189194
var toolingApi = self.vlocity.jsForceConnection.tooling;
@@ -296,6 +301,9 @@ DataPacksJob.prototype.buildManifestFromQueries = function(jobInfo, onComplete)
296301
var totalFound = 0;
297302

298303
async.eachSeries(jobInfo.queries, function(queryData, callback) {
304+
if (!queryData || !queryData.VlocityDataPackType) {
305+
return callback();
306+
}
299307

300308
if (!jobInfo.manifest[queryData.VlocityDataPackType]) {
301309
jobInfo.manifest[queryData.VlocityDataPackType] = [];
@@ -752,7 +760,7 @@ DataPacksJob.prototype.activateAll = function(dataPackData, jobInfo, onComplete,
752760

753761
dataPackData.dataPacks.forEach(function(dataPack) {
754762

755-
if (dataPack.ActivationStatus == 'Ready' && dataPack.VlocityDataPackStatus == 'Success') {
763+
if (dataPack.ActivationStatus == 'Ready' && dataPack.VlocityDataPackStatus == 'Success') {
756764

757765
// If it is the only one in the deploy and it fails to activate it must be set to error. Otherwise retry the deploy and activation separate from others.
758766
if (dataPackData.dataPacks.length == 1) {
@@ -767,6 +775,16 @@ DataPacksJob.prototype.activateAll = function(dataPackData, jobInfo, onComplete,
767775
} else {
768776
jobInfo.currentStatus[dataPack.VlocityDataPackKey] = 'ReadySeparate';
769777
}
778+
} else if (dataPack.ActivationStatus == 'Error') {
779+
780+
var message = 'Activation Error >> ' + dataPack.VlocityDataPackKey + ' --- ' + dataPack.ActivationMessage;
781+
782+
jobInfo.hasError = true;
783+
jobInfo.currentStatus[dataPack.VlocityDataPackKey] = 'Error';
784+
785+
if (jobInfo.errors.indexOf(message) == -1) {
786+
jobInfo.errors.push(message);
787+
}
770788
}
771789
});
772790

node_vlocity/datapacksutils.js

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var fs = require("fs-extra");
22
var path = require('path');
33
var stringify = require('json-stable-stringify');
44
var async = require('async');
5+
var yaml = require('js-yaml');
56

67
// use consts for setting the namespace prefix so that we easily can reference it later on in this file
78
const namespacePrefix = 'vlocity_namespace';
@@ -647,17 +648,49 @@ DataPacksUtils.prototype.printJobStatus = function(jobInfo) {
647648
return;
648649
}
649650

650-
Object.keys(jobInfo.currentStatus).forEach(function(dataPackKey) {
651+
var keysByStatus = {};
652+
653+
Object.keys(jobInfo.currentStatus).forEach(function(dataPackKey) {
654+
655+
var status = jobInfo.currentStatus[dataPackKey];
651656
if (jobInfo.currentStatus[dataPackKey] == 'Ready'
652657
|| jobInfo.currentStatus[dataPackKey] == 'Header'
653658
|| jobInfo.currentStatus[dataPackKey] == 'Added'
654659
|| jobInfo.currentStatus[dataPackKey] == 'ReadySeparate') {
660+
status = 'Remaining';
655661
totalRemaining++;
656662
} else if (jobInfo.currentStatus[dataPackKey] == 'Error') {
657663
errorsCount++;
658664
} else if (jobInfo.currentStatus[dataPackKey] == 'Success') {
659665
successfulCount++;
660666
}
667+
668+
if (!keysByStatus[status]) {
669+
keysByStatus[status] = {};
670+
}
671+
672+
// For Exports
673+
var keyForStatus = jobInfo.vlocityKeysToNewNamesMap[dataPackKey] ? jobInfo.vlocityKeysToNewNamesMap[dataPackKey] : dataPackKey;
674+
675+
if (keyForStatus.indexOf('/') != -1) {
676+
677+
var slashIndex = keyForStatus.indexOf('/');
678+
var beforeSlash = keyForStatus.substring(0, slashIndex);
679+
var afterSlash = keyForStatus.substring(slashIndex+1);
680+
681+
if (!keysByStatus[status][beforeSlash]) {
682+
keysByStatus[status][beforeSlash] = [];
683+
}
684+
var dataPackName = jobInfo.generatedKeysToNames[keyForStatus];
685+
686+
if (dataPackName && afterSlash.indexOf(dataPackName) == -1) {
687+
afterSlash = dataPackName + ' - ' + afterSlash;
688+
}
689+
690+
if (keysByStatus[status][beforeSlash].indexOf(afterSlash) == -1) {
691+
keysByStatus[status][beforeSlash].push(afterSlash);
692+
}
693+
}
661694
});
662695

663696
if (jobInfo.extendedManifest) {
@@ -693,4 +726,25 @@ DataPacksUtils.prototype.printJobStatus = function(jobInfo) {
693726
if (jobInfo.hasError) {
694727
jobInfo.errorMessage = jobInfo.errors.join('\n');
695728
}
729+
730+
Object.keys(keysByStatus).forEach(function(statusKey) {
731+
Object.keys(keysByStatus[statusKey]).forEach(function(typeKey) {
732+
keysByStatus[statusKey][typeKey].sort();
733+
});
734+
});
735+
736+
var logInfo = {
737+
Job: jobInfo.jobName,
738+
Action: jobInfo.jobAction,
739+
ProjectPath: jobInfo.projectPath,
740+
TotalTime: Math.floor((elapsedTime / 60)) + 'm ' + Math.floor((elapsedTime % 60)) + 's',
741+
Errors: jobInfo.errors,
742+
Status: keysByStatus
743+
};
744+
745+
try {
746+
fs.outputFileSync(path.join('logs', jobInfo.logName), yaml.dump(logInfo, { lineWidth: 1000 }));
747+
} catch (e) {
748+
console.log(e);
749+
}
696750
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"VlocityCard/datapacktest-card": "Reference by Name"
3+
}

0 commit comments

Comments
 (0)