Skip to content

Commit

Permalink
Added build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
nkimaina committed Apr 26, 2019
1 parent b7babcf commit 0553501
Show file tree
Hide file tree
Showing 8 changed files with 315 additions and 17 deletions.
52 changes: 52 additions & 0 deletions build-hiv-summary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

let QueryRunner = require('./query-runner');

let queryRunner = new QueryRunner().getInstance();

class BuildHivSummary {

constructor() {

}

runJob() {
return new Promise((resolve, reject) => {
let sql = `select count(*) as items_in_queue from etl.flat_hiv_summary_build_queue`;

queryRunner.runQuery(sql)
.then((result) => {
let items = result.results[0].items_in_queue;
console.log('Items in queue:' + items);

let batches = items < 50 ? 1 : items / 50;
batches = Math.ceil(batches);
console.log('batches: ' + batches);

let queries = [];

for(let i =0; i < batches; i++) {
let qry = `call generate_hiv_summary_v15_7("build",${i},50,20);`;
queries.push(queryRunner.runQuery(qry));
}

Promise.all(queries).then((results)=>{
console.log('finished running all the queries', results);
resolve(results);
}).catch((err)=>{
reject(err);
console.error('Error running all the queries', err);
});

//resolve(parallelism)
})
.catch((err) => {
// handle error
reject(err);
});

});
}

}

module.exports = BuildHivSummary;
29 changes: 29 additions & 0 deletions cleanup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Object to capture process exits and call app specific cleanup function

function noOp() {};

exports.Cleanup = function Cleanup(callback) {

// attach user callback to the process event emitter
// if no callback, it will still exit gracefully on Ctrl-C
callback = callback || noOp;
process.on('cleanup',callback);

// do app specific cleaning before exiting
process.on('exit', function () {
process.emit('cleanup');
});

// catch ctrl+c event and exit normally
process.on('SIGINT', function () {
console.log('Ctrl-C...');
process.exit(2);
});

//catch uncaught exceptions, trace, then exit normally
process.on('uncaughtException', function(e) {
console.log('Uncaught Exception...');
console.log(e.stack);
process.exit(99);
});
};
9 changes: 9 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
let config = {
host : 'localhost',
user : 'admin',
password: 'admin',
database: 'test'
};


module.exports = config;
21 changes: 21 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
let BuildHivSummary = require('./build-hiv-summary');
let ScheduleHivSummary = require('./schedule-hiv-summary');
let Moment = require('moment');
try {
let buildJob = new BuildHivSummary();
let startedAt = Moment();
console.log('Starting at:', startedAt.toLocaleString())
buildJob.runJob().then(() => {
console.log('Finshed all jobs.');
let endedAt = Moment();
let diff = endedAt.diff(startedAt, 'seconds');
console.log('Took ' + diff + ' seconds.');
}).catch((err) => {
console.error('error running hiv summary job');
throw err;
});
} catch (error) {
console.error('Error running pipeline', error);
}

process.stdin.resume();
97 changes: 82 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "etl-sync-scripts",
"version": "1.0.0",
"version": "0.1.0",
"description": "",
"main": "index.js",
"directories": {
Expand All @@ -9,7 +9,9 @@
"test": "test"
},
"dependencies": {
"chai": "^4.2.0"
"chai": "^4.2.0",
"moment": "^2.24.0",
"mysql": "^2.16.0"
},
"devDependencies": {
"mocha": "^5.2.0"
Expand Down
Loading

0 comments on commit 0553501

Please sign in to comment.