Compare commits

..

No commits in common. "0f69947b6d06e66a742c122c5bdca62a439b83fc" and "7296410b1252aaa5996d6f7a998f3c772b9c0f1c" have entirely different histories.

7 changed files with 30 additions and 91 deletions

2
.gitignore vendored
View File

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

View File

@ -13,7 +13,6 @@ This supports mailing for logging what is happening to the databases, future pla
- [ ] Email the log through email
- [ ] Discord WebHook
- [ ] Telegram Hook
- [ ] Docker Support
### How to Use
1. Setup the configuration file which is [This file](./config.example.json) and rename it into `config.json` instead of `config.example.json`.

View File

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

View File

View File

@ -41,15 +41,7 @@ async function main() {
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);
}
await w.startProcessing();
}
}

View File

@ -1,4 +1,3 @@
import * as mysql from "mysql";
import { NodeConnection } from "../helper/config";
import { uuid } from "../helper/mainHelper";
@ -28,11 +27,6 @@ export class DataWorker {
this.id = uuid();
}
public getID() : string {
return this.id;
}
public addNodeTask(node: NodeConnection) {
// Add the task to the list
this.nodeTasks.push(node);
@ -41,34 +35,31 @@ export class DataWorker {
/**
* Start processing the node tasks.
*/
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>> = [];
public async startProcessing() : Promise<void> {
// 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;
// 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>> = [];
// Add the process to the queue
taskQueue.push(this.processTask(this.nodeTasks[i]))
// Add to the index
i++;
}
// 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;
// Return the resulting resolves
_r(await Promise.allSettled(taskQueue));
}
} catch ( ex ) {
_e(ex);
// 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);
}
}
@ -76,47 +67,8 @@ export class DataWorker {
* Process a task
* @param task The task to process
*/
private processTask(task: NodeConnection) {
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}`);
})
private async processTask(task: NodeConnection) {
return `[${this.id}]: Succesfully ran task ${task.name}`;
}
}

View File

@ -4,9 +4,9 @@
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */
"target": "ES2015", /* 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'. */
"lib": ["ES2020", "ES2020.Promise"], /* Specify library files to be included in the compilation. */
"lib": ["DOM", "ES2015", "ES2015.Promise"], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "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. */
// "composite": true, /* Enable project compilation */
// "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. */
// "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'. */
@ -32,7 +32,7 @@
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "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 */
// "noUnusedLocals": true, /* Report errors on unused locals. */