This repository has been archived on 2024-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
DataHoard/src/app.ts

59 lines
1.6 KiB
TypeScript
Raw Normal View History

// Import the configuration file
import { getConfig, NodeConnection } from "./helper/config";
2021-08-21 15:46:30 +03:00
// Import SystemControl
import { SystemControl } from "./models/SystemController";
// Import the worker processes
import { DataWorker } from "./models/WorkerProcess";
2021-08-21 15:46:30 +03:00
// Global system control singleton
((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() {
// Get the configuration file
const config = getConfig();
2021-08-21 01:21:16 +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 ) {
let resolves: PromiseSettledResult<any>[] = await w.startProcessing();
for( let r of resolves ) {
const reason = (r as any).reason;
console.log(w.getID(), r);
}
}
}
// Run the main program
main();