Compare commits
2 Commits
7296410b12
...
0f69947b6d
Author | SHA1 | Date |
---|---|---|
Daniel Legt | 0f69947b6d | |
Daniel Legt | db35be9517 |
|
@ -120,5 +120,7 @@ out
|
|||
|
||||
dist/*
|
||||
!dist/.keep
|
||||
release/*
|
||||
!release/.keep
|
||||
package-lock.json
|
||||
config.json
|
||||
|
|
|
@ -13,6 +13,7 @@ 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`.
|
||||
|
|
|
@ -8,7 +8,9 @@
|
|||
"description": "Make sure your database backups run and keep track of performance",
|
||||
"version": "0.1.0",
|
||||
"main": "dist/app.js",
|
||||
"devDependencies": {},
|
||||
"devDependencies": {
|
||||
"@types/mysql": "^2.15.19"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "tsc && node dist/app.js"
|
||||
},
|
||||
|
|
10
src/app.ts
10
src/app.ts
|
@ -41,7 +41,15 @@ async function main() {
|
|||
console.log(`Succesfully added ${config.nodes.length} Tasks to ${workerNodes.length} Workers`);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import * as mysql from "mysql";
|
||||
import { NodeConnection } from "../helper/config";
|
||||
import { uuid } from "../helper/mainHelper";
|
||||
|
||||
|
@ -27,6 +28,11 @@ 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);
|
||||
|
@ -35,8 +41,9 @@ export class DataWorker {
|
|||
/**
|
||||
* 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
|
||||
|
@ -51,15 +58,17 @@ export class DataWorker {
|
|||
// Add the process to the queue
|
||||
taskQueue.push(this.processTask(this.nodeTasks[i]))
|
||||
// Add to the index
|
||||
i += x;
|
||||
i++;
|
||||
}
|
||||
|
||||
// Get the results of the running
|
||||
const runResults = await Promise.all(taskQueue);
|
||||
|
||||
console.log(runResults);
|
||||
|
||||
// Return the resulting resolves
|
||||
_r(await Promise.allSettled(taskQueue));
|
||||
}
|
||||
} catch ( ex ) {
|
||||
_e(ex);
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -67,8 +76,47 @@ export class DataWorker {
|
|||
* Process a task
|
||||
* @param task The task to process
|
||||
*/
|
||||
private async processTask(task: NodeConnection) {
|
||||
return `[${this.id}]: Succesfully ran task ${task.name}`;
|
||||
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}`);
|
||||
})
|
||||
}
|
||||
|
||||
}
|
|
@ -4,9 +4,9 @@
|
|||
|
||||
/* Basic Options */
|
||||
// "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'. */
|
||||
"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. */
|
||||
// "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. */
|
||||
|
|
Reference in New Issue