* Copyright (c) 2018 Zachary Kniebel. All rights reserved.
* NOTICE: All information contained herein is, and remains the
* property of Zachary Kniebel. The intellectual and technical
* concepts contained herein are proprietary to Zachary Kniebel and
* may be covered by U.S. and Foreign Patents, patents in process,
* and are protected by trade secret or copyright law. Dissemination
* of this information or reproduction of this material is strictly
* forbidden unless prior written permission is obtained from Zachary
const amqp = require('amqplib/callback_api');
const request = require('request');
* Optionally closes the connection and exits with the given exit code
* @param {object} process process object to exit
* @param {integer} exitCode exit code value to be passed upon exiting
* @param {object} connection (optional) connection to be closed
var _exitProgram = function(process, exitCode, connection) {
var args = process.argv.slice(2);
var connectionString = args[0];
console.log("No connectionString was passed. Program terminating without sending.");
amqp.connect(connectionString, function(err, conn) {
conn.createChannel(function(err, ch) {
var jsonGetUrl = args[1];
console.log("No jsonGetUrl was passed. Program terminating without sending.");
_exitProgram(process, 1, conn);
console.log("No queue was passed. Program terminating without sending.");
_exitProgram(process, 1, conn);
request(jsonGetUrl, (err, res, data) => {
return console.error(err);
_exitProgram(process, 1, conn);
var json = JSON.parse(data);
console.error("An error occurred while retrieving the architecture data. Program terminating...", json);
_exitProgram(process, 1, conn);
var completionHandlers = args[3];
json.Data.CompletionHandlers = JSON.parse(completionHandlers);
data = JSON.stringify(json);
console.log("Architecture data received. Forwarding to generation_queue...");
ch.assertQueue(queue, {durable: false});
ch.sendToQueue(queue, Buffer.from(data));
console.log(" [x] Sent %s bytes to the generation_queue", data.length);
setTimeout(function() { _exitProgram(process, 0, conn) }, 500);