Compare commits
No commits in common. "0f69947b6d06e66a742c122c5bdca62a439b83fc" and "7296410b1252aaa5996d6f7a998f3c772b9c0f1c" have entirely different histories.
0f69947b6d
...
7296410b12
|
@ -120,7 +120,5 @@ out
|
||||||
|
|
||||||
dist/*
|
dist/*
|
||||||
!dist/.keep
|
!dist/.keep
|
||||||
release/*
|
|
||||||
!release/.keep
|
|
||||||
package-lock.json
|
package-lock.json
|
||||||
config.json
|
config.json
|
||||||
|
|
|
@ -13,7 +13,6 @@ This supports mailing for logging what is happening to the databases, future pla
|
||||||
- [ ] Email the log through email
|
- [ ] Email the log through email
|
||||||
- [ ] Discord WebHook
|
- [ ] Discord WebHook
|
||||||
- [ ] Telegram Hook
|
- [ ] Telegram Hook
|
||||||
- [ ] Docker Support
|
|
||||||
|
|
||||||
### How to Use
|
### 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`.
|
1. Setup the configuration file which is [This file](./config.example.json) and rename it into `config.json` instead of `config.example.json`.
|
||||||
|
|
|
@ -8,9 +8,7 @@
|
||||||
"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"
|
||||||
},
|
},
|
||||||
|
|
10
src/app.ts
10
src/app.ts
|
@ -41,15 +41,7 @@ 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 ) {
|
||||||
let resolves: PromiseSettledResult<any>[] = await w.startProcessing();
|
await w.startProcessing();
|
||||||
|
|
||||||
for( let r of resolves ) {
|
|
||||||
const reason = (r as any).reason;
|
|
||||||
|
|
||||||
|
|
||||||
console.log(w.getID(), r);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
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";
|
||||||
|
|
||||||
|
@ -28,11 +27,6 @@ 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);
|
||||||
|
@ -41,34 +35,31 @@ export class DataWorker {
|
||||||
/**
|
/**
|
||||||
* Start processing the node tasks.
|
* Start processing the node tasks.
|
||||||
*/
|
*/
|
||||||
public startProcessing() : Promise<PromiseSettledResult<any>[]> {
|
public async startProcessing() : Promise<void> {
|
||||||
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
|
// Go through all of the tasks to run
|
||||||
for ( let x = 0; x < this.parallelTasksCount; x++ ) {
|
for ( let i = 0; i < this.nodeTasks.length; i++ ) {
|
||||||
// Check if we have stept out of bounds
|
// Spawn in the task queue
|
||||||
if ( i >= this.nodeTasks.length ) // Ignore out-of-bounds
|
let taskQueue : Array<Promise<any>> = [];
|
||||||
break;
|
|
||||||
|
|
||||||
// Add the process to the queue
|
// Start running the parallel tasks
|
||||||
taskQueue.push(this.processTask(this.nodeTasks[i]))
|
for ( let x = 0; x < this.parallelTasksCount; x++ ) {
|
||||||
// Add to the index
|
// Check if we have stept out of bounds
|
||||||
i++;
|
if ( i >= this.nodeTasks.length ) // Ignore out-of-bounds
|
||||||
}
|
break;
|
||||||
|
|
||||||
// Return the resulting resolves
|
// Add the process to the queue
|
||||||
_r(await Promise.allSettled(taskQueue));
|
taskQueue.push(this.processTask(this.nodeTasks[i]))
|
||||||
}
|
// Add to the index
|
||||||
} catch ( ex ) {
|
i += x;
|
||||||
_e(ex);
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
|
// 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
|
* Process a task
|
||||||
* @param task The task to process
|
* @param task The task to process
|
||||||
*/
|
*/
|
||||||
private processTask(task: NodeConnection) {
|
private async processTask(task: NodeConnection) {
|
||||||
return new Promise<string>( async (_r, _e) => {
|
return `[${this.id}]: Succesfully ran task ${task.name}`;
|
||||||
// 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}`);
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -4,9 +4,9 @@
|
||||||
|
|
||||||
/* Basic Options */
|
/* Basic Options */
|
||||||
// "incremental": true, /* Enable incremental compilation */
|
// "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'. */
|
"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. */
|
// "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. */
|
||||||
|
|
Reference in New Issue