Slight refactoring + optimizations

dependabot/npm_and_yarn/BuildServer/eslint-7.2.0
Inga 🏳‍🌈 8 years ago
parent c4cc3a6eb3
commit cbc33b4ad4
  1. 12
      BuildServer/lib/report-processor.js
  2. 4
      BuildServer/lib/task-processor.js
  3. 10
      BuildServer/lib/tasks/index.js

@ -11,12 +11,16 @@ const reportFilename = "report.json.gz";
const writeReport = (releaseDir, err, result, callback) => { const writeReport = (releaseDir, err, result, callback) => {
const readable = new streamBuffers.ReadableStreamBuffer(); const readable = new streamBuffers.ReadableStreamBuffer();
const writeStream = fs.createWriteStream(path.join(releaseDir, reportFilename));
readable readable
.pipe(zlib.createGzip()) .pipe(zlib.createGzip())
.pipe(fs.createWriteStream(path.join(releaseDir, reportFilename))) .pipe(writeStream)
.on("error", callback) .on("error", callback)
.on("finish", callback); .on("finish", () => {
writeStream.close();
callback();
});
readable.put(JSON.stringify({ readable.put(JSON.stringify({
"date": Date.now(), "date": Date.now(),
@ -35,6 +39,8 @@ const readReport = (releaseDir, callback) => {
.pipe(writable) .pipe(writable)
.on("error", callback) .on("error", callback)
.on("finish", () => { .on("finish", () => {
readStream.destroy();
const data = writable.getContentsAsString(); const data = writable.getContentsAsString();
if (!data) { if (!data) {
@ -45,6 +51,8 @@ const readReport = (releaseDir, callback) => {
}); });
}; };
exports.readReport = readReport;
exports.writeReport = writeReport; exports.writeReport = writeReport;
exports.loadReport = (app, options, callback) => { exports.loadReport = (app, options, callback) => {

@ -1,5 +1,7 @@
"use strict"; "use strict";
const tasks = require("./tasks");
// TaskProcessor does not look like EventEmitter, so no need to extend EventEmitter and use `emit' here. // TaskProcessor does not look like EventEmitter, so no need to extend EventEmitter and use `emit' here.
const TaskProcessor = function (task, outerProcessor, callback) { const TaskProcessor = function (task, outerProcessor, callback) {
if (!this) { if (!this) {
@ -38,7 +40,7 @@ const TaskProcessor = function (task, outerProcessor, callback) {
that.done = done; that.done = done;
that.context = outerProcessor.context; that.context = outerProcessor.context;
const taskImpl = require(`./tasks/${task.type.match(/[\w\-]/g).join("")}`); const taskImpl = tasks[task.type];
taskWorker = taskImpl(task.params || {}, that); taskWorker = taskImpl(task.params || {}, that);

@ -0,0 +1,10 @@
"use strict";
// Code taken from http://stackoverflow.com/a/17204293
require("fs").readdirSync(__dirname).forEach((file) => {
if (file.match(/\.js$/) !== null && file !== "index.js") {
const name = file.replace(".js", "");
exports[name] = require(`./${file}`);
}
});
Loading…
Cancel
Save