+ A lot of progress overall

+ Upped JS Version as I don't really see a reason why not.
This commit is contained in:
Daniel Legt 2021-08-21 18:40:44 +03:00
parent db35be9517
commit 0f69947b6d
6 changed files with 90 additions and 30 deletions

2
.gitignore vendored
View File

@ -120,5 +120,7 @@ out
dist/* dist/*
!dist/.keep !dist/.keep
release/*
!release/.keep
package-lock.json package-lock.json
config.json config.json

View File

@ -8,7 +8,9 @@
"description": "Make sure your database backups run and keep track of performance", "description": "Make sure your database backups run and keep track of performance",
"version": "0.1.0", "version": "0.1.0",
"main": "dist/app.js", "main": "dist/app.js",
"devDependencies": {}, "devDependencies": {
"@types/mysql": "^2.15.19"
},
"scripts": { "scripts": {
"start": "tsc && node dist/app.js" "start": "tsc && node dist/app.js"
}, },

0
release/.keep Normal file
View File

View File

@ -41,7 +41,15 @@ async function main() {
console.log(`Succesfully added ${config.nodes.length} Tasks to ${workerNodes.length} Workers`); console.log(`Succesfully added ${config.nodes.length} Tasks to ${workerNodes.length} Workers`);
for( let w of workerNodes ) { for( let w of workerNodes ) {
await w.startProcessing(); let resolves: PromiseSettledResult<any>[] = await w.startProcessing();
for( let r of resolves ) {
const reason = (r as any).reason;
console.log(w.getID(), r);
}
} }
} }

View File

@ -1,3 +1,4 @@
import * as mysql from "mysql";
import { NodeConnection } from "../helper/config"; import { NodeConnection } from "../helper/config";
import { uuid } from "../helper/mainHelper"; import { uuid } from "../helper/mainHelper";
@ -27,6 +28,11 @@ export class DataWorker {
this.id = uuid(); this.id = uuid();
} }
public getID() : string {
return this.id;
}
public addNodeTask(node: NodeConnection) { public addNodeTask(node: NodeConnection) {
// Add the task to the list // Add the task to the list
this.nodeTasks.push(node); this.nodeTasks.push(node);
@ -35,31 +41,34 @@ export class DataWorker {
/** /**
* Start processing the node tasks. * Start processing the node tasks.
*/ */
public async startProcessing() : Promise<void> { public startProcessing() : Promise<PromiseSettledResult<any>[]> {
return new Promise( async (_r, _e) => {
try {
// Go through all of the tasks to run
for ( let i = 0; i < this.nodeTasks.length; i++ ) {
// Spawn in the task queue
let taskQueue : Array<Promise<any>> = [];
// Start running the parallel tasks
for ( let x = 0; x < this.parallelTasksCount; x++ ) {
// Check if we have stept out of bounds
if ( i >= this.nodeTasks.length ) // Ignore out-of-bounds
break;
// Add the process to the queue
taskQueue.push(this.processTask(this.nodeTasks[i]))
// Add to the index
i++;
}
// Go through all of the tasks to run // Return the resulting resolves
for ( let i = 0; i < this.nodeTasks.length; i++ ) { _r(await Promise.allSettled(taskQueue));
// Spawn in the task queue }
let taskQueue : Array<Promise<any>> = []; } catch ( ex ) {
_e(ex);
// Start running the parallel tasks
for ( let x = 0; x < this.parallelTasksCount; x++ ) {
// Check if we have stept out of bounds
if ( i >= this.nodeTasks.length ) // Ignore out-of-bounds
break;
// Add the process to the queue
taskQueue.push(this.processTask(this.nodeTasks[i]))
// Add to the index
i += x;
} }
})
// Get the results of the running
const runResults = await Promise.all(taskQueue);
console.log(runResults);
}
} }
@ -67,8 +76,47 @@ export class DataWorker {
* Process a task * Process a task
* @param task The task to process * @param task The task to process
*/ */
private async processTask(task: NodeConnection) { private processTask(task: NodeConnection) {
return `[${this.id}]: Succesfully ran task ${task.name}`; return new Promise<string>( async (_r, _e) => {
// Connect to the mysql database to test out the connection
const conn : mysql.Connection = mysql.createConnection({
host: task.hostname,
port: task.port,
user: task.username,
password: task.password,
});
try { // Try and connect to the database
// Connect to the database
await new Promise<void>( (rez, err) => {
conn.connect(e => {
if ( !!e ) {
// Mark the results as failure
err(e);
}
// Mark the promise as done
rez();
})
})
} catch ( error ) { // Return the connection error upstream
return _e(error);
}
// Check if we have target
try { // Close the connection
await new Promise<void>((re, er) => {
conn.end( err => {
// Just ignore it, whatever.
re();
});
})
} catch ( err ) {};
// Stop the code and mark as success
_r(`Succesfully ran task ${task.name}`);
})
} }
} }

View File

@ -4,9 +4,9 @@
/* Basic Options */ /* Basic Options */
// "incremental": true, /* Enable incremental compilation */ // "incremental": true, /* Enable incremental compilation */
"target": "ES2015", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */ "target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
"lib": ["DOM", "ES2015", "ES2015.Promise"], /* Specify library files to be included in the compilation. */ "lib": ["ES2020", "ES2020.Promise"], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */ // "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */ // "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
@ -18,7 +18,7 @@
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */ // "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */ "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */ // "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */ // "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
@ -32,7 +32,7 @@
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */ /* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */ // "noUnusedLocals": true, /* Report errors on unused locals. */