I have a node script that calls many processes to package up files. Most of the time, this works great, however once in a while (maybe on average 1 out of every 5 calls?) it just stops in the middle, always in the same spot. Specifically, the end of the log when it fails looks like:
Finished task 1!
Compiling jsajax.js...
Compiling apps.js...
I don't get any errors or anything so I'm not sure what to even look at. The setup here is my main file (index.js) uses co and generators to call the async processes required, and yield their results. Some of this is with gulp, which is where this issue is happening. I am including the calling code and the gulp task here as the rest of the code is too long to show everything. I am happy to include more if you think it is needed. Thanks!
Calling Function:
const createJS = function* createJS () {
try {
yield gulpFile.createJS();
return 0;
} catch(err) {
console.error(err);
return CONSTANTS.ERROR;
}
};
Gulp task:
const createJS = function () {
const buildProps = PropertiesReader('build.properties'),
distLoc = buildProps.get('distLoc'),
installLoc = buildProps.get('installLoc'),
updateLoc = buildProps.get('updateLoc'),
installJSLoc = `${installLoc}/js`,
updateJSLoc = `${updateLoc}/js`,
jsajax = CONSTANTS.JSAJAX_FILES.map(file => distLoc + file),
appsOnly = CONSTANTS.APPS_FILES.map(file => distLoc + file),
apps = [...jsajax, ...appsOnly];
let compile1, compile2;
compile1 = new Promise((resolve, reject) => {
console.log('Compiling jsajax.js...');
gulp.src(jsajax)
.pipe(sourcemaps.init())
.pipe(concat('jsajax.js'))
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(installJSLoc))
.pipe(gulp.dest(updateJSLoc))
.on('error', err => reject(err))
.on('end', () => {
console.log('jsajax.js compiled successfully!');
resolve();
});
});
compile2 = new Promise((resolve, reject) => {
console.log('Compiling apps.js...');
gulp.src(apps)
.pipe(sourcemaps.init())
.pipe(concat('apps.js'))
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(installJSLoc))
.pipe(gulp.dest(updateJSLoc))
.on('error', err => reject(err))
.on('end', () => {
console.log('apps.js compiled successfully!');
resolve();
});
});
return Promise.all([compile1, compile2]);
};