2021-08-21 16:11:09 +03:00
|
|
|
// Import the configuration file
|
2021-08-21 17:50:54 +03:00
|
|
|
import { getConfig, NodeConnection } from "./helper/config";
|
2021-08-21 15:46:30 +03:00
|
|
|
// Import SystemControl
|
2021-08-21 02:26:59 +03:00
|
|
|
import { SystemControl } from "./models/SystemController";
|
2021-08-21 17:50:54 +03:00
|
|
|
// Import the worker processes
|
|
|
|
import { DataWorker } from "./models/WorkerProcess";
|
2021-08-21 02:26:59 +03:00
|
|
|
|
2021-08-21 15:46:30 +03:00
|
|
|
// Global system control singleton
|
2021-08-21 17:50:54 +03:00
|
|
|
((global as any).logger as SystemControl) = new SystemControl();
|
2021-08-21 00:56:51 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The main function to run the program with
|
|
|
|
*/
|
|
|
|
async function main() {
|
2021-08-21 16:11:09 +03:00
|
|
|
// Get the configuration file
|
2021-08-21 17:50:54 +03:00
|
|
|
const config = getConfig();
|
2021-08-21 01:21:16 +03:00
|
|
|
|
2021-08-21 17:50:54 +03:00
|
|
|
// Initialize the Worker Nodes array
|
|
|
|
let workerNodes : Array<DataWorker> = [];
|
|
|
|
|
|
|
|
// Spawn in the DataWorkers
|
|
|
|
for ( let i: number = 0; i < config.options.parallel_nodes; i++ ) {
|
|
|
|
// Create a new data worker
|
|
|
|
workerNodes.push(new DataWorker(config.options.parallel_node_tasks));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Keep track of the worker that is assigned this node
|
|
|
|
*/
|
|
|
|
let workerIndex = 0;
|
|
|
|
// Start assigning nodes to the DataWorkers
|
|
|
|
for ( let node of config.nodes ) {
|
|
|
|
console.log(`Adding workerIndex[${workerIndex}]`);
|
|
|
|
// Add the task to the node
|
|
|
|
workerNodes[workerIndex].addNodeTask(node);
|
|
|
|
// Increment the worker index
|
|
|
|
workerIndex++;
|
|
|
|
if ( workerIndex >= workerNodes.length ) workerIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(`Succesfully added ${config.nodes.length} Tasks to ${workerNodes.length} Workers`);
|
|
|
|
|
|
|
|
for( let w of workerNodes ) {
|
|
|
|
await w.startProcessing();
|
|
|
|
}
|
2021-08-21 16:11:09 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Run the main program
|
|
|
|
main();
|