Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
additionalFlags: [
'--window-size=1020,720',
'--disable-gpu',
'--headless'
]
});
return launcher.run().then(() => launcher)
.catch(err => {
return launcher.kill().then(() => { // Kill Chrome if there's an error.
throw err;
}, console.error);
});
}
lockfile.lock(output+'.lock', function(err) {
if (err) {
// Another process is already working on this. Just wait until it's finished.
console.log("Waiting for other process")
lockfile.lock(output+'.lock', { wait: timeout }, function(err) {
process.exit(0)
})
} else {
run().catch(e => {
if (e.code == "ECONNREFUSED") {
launchChrome().then(run).catch(e => {
console.error(e);
process.exit(1);
})
} else {
console.error(e);
process.exit(1);
initialize: function(updateInterval, callback) {
this.updateInterval = updateInterval;
this.updateCallback = callback;
// Perform a lock while updating the cache to ensure only one process
// is updating the cache at a time.
lockFile.lock(this.cacheLockPath, { stale: 60 * 1000 }, function(error) {
if(error) {
this.finish(null, cache);
return true;
}
fs.stat(this.cachePath, this.handleFileStat.bind(this));
}.bind(this));
},
return new Promise(function (resolve, reject) {
var lockPath = getLockPath(file);
/* eslint-disable consistent-return */
lockfile.lock(lockPath, function (err) {
if (err) {
return reject(err);
}
resolve();
});
});
};
function then () {
var opts = { stale: npm.config.get("cache-lock-stale")
, retries: npm.config.get("cache-lock-retries")
, wait: npm.config.get("cache-lock-wait") }
var lf = lockFileName(u)
log.verbose("lock", u, lf)
lockFile.lock(lf, opts, function(er) {
if (!er) myLocks[lf] = true
cb(er)
})
}
}
function then () {
var opts = { stale: npm.config.get("cache-lock-stale")
, retries: npm.config.get("cache-lock-retries")
, wait: npm.config.get("cache-lock-wait") }
var lf = lockFileName(u)
log.verbose("lock", u, lf)
lockFile.lock(lf, opts, function(er) {
if (!er) myLocks[lf] = true
cb(er)
})
}
}
getCacheStat(function (er, cs) {
if (er) return cb(er)
var opts = { stale: npm.config.get("cache-lock-stale")
, retries: npm.config.get("cache-lock-retries")
, wait: npm.config.get("cache-lock-wait") }
var lf = lockFileName(u)
log.verbose("lock", u, lf)
lockFile.lock(lf, opts, function(er) {
if (!er) myLocks[lf] = true
cb(er)
})
})
}
lockMutex: function (done) {
lockFile.lock(mutexPath, function (error) {
if (error && error.code === 'EEXIST') {
error.description = 'Could not open data store because files are locked by another instance. If no other instance, manually delete ' + error.path;
}
done(error);
});
},
loadData: ['lockMutex', function (done) {
saveRuntime: function(callback) {
lockFile.lock(this.runtimeLockPath, {}, function() {
var data = yaml.safeDump(this.runtimeValues || {});
logger.info('Writing new config (PID ' + process.pid + ')...');
logger.debug(data);
atomic.writeFile(this.runtimePath, data, function(error) {
if(callback) {
callback(error);
}
});
}.bind(this));
},
respondFromCache: function(callback) {
logger.info(this.requestLogId + ' - Delivering cached response');
lockfile.lock(this.lockCachePath, { wait: 500, stale: 60000 }, function(error) {
callback(error);
fs.readFile(this.metaCachePath, function(error, data) {
var metadata = JSON.parse(data);
this.response.writeHead(metadata.statusCode, metadata.headers);
var bodyFile = fs.createReadStream(this.bodyCachePath);
bodyFile.pipe(this.response);
bodyFile.on('end', function() {
lockfile.unlock(this.lockCachePath, function() {
});
}.bind(this));
}.bind(this));
}.bind(this));
},