-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
828d646
commit 56fb2fc
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RESULTS_PATH = void 0; | ||
var asyncLib = require("async"); | ||
var fs = require("fs"); | ||
var net = require("net"); | ||
// will just write to wherever the process is running, but the server needs to be launched from the same directory so we use an abs path | ||
exports.RESULTS_PATH = "".concat(__dirname, "/results.json"); | ||
function launchQueueServer() { | ||
// Create a write to result.json queue with a concurrency of 1 | ||
// Possibly the simplest fix would be to run this as a separate process, then we can enforce messages sent to this queue are processed in order | ||
var queue = asyncLib.queue(function (task, callback) { | ||
console.log('received task', task.analysisKey); | ||
// return new Promise<void>((resolve, reject) => { | ||
var results = task.results, analysisKey = task.analysisKey; | ||
try { | ||
fs.writeFileSync(exports.RESULTS_PATH, JSON.stringify(results, null, 2)); | ||
console.log("Analysis \"".concat(analysisKey, "\" has been written to ").concat(exports.RESULTS_PATH)); | ||
} | ||
catch (err) { | ||
console.error('Error writing to results.json', err); | ||
} | ||
// }); | ||
}, 1); | ||
queue.drain(function () { | ||
console.log('all items have been processed'); | ||
}); | ||
// this event listener receives tasks from the parallel processes | ||
var server = net.createServer(function (socket) { | ||
socket.on('data', function (data) { | ||
var task = JSON.parse(data.toString()); | ||
queue.push(task); | ||
}); | ||
}); | ||
console.log('Queue server listening on port 8000'); | ||
server.listen(8000); | ||
} | ||
// for use with zst_decompresser.js | ||
if (require.main === module) { | ||
launchQueueServer(); | ||
} |