Skip to content

Commit

Permalink
Close databases (async function) in a way that it is actually carried…
Browse files Browse the repository at this point in the history
  • Loading branch information
tristan.ramseyer committed May 6, 2022
1 parent d83a638 commit e00e4cd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
12 changes: 10 additions & 2 deletions cell-geolocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,19 @@ http.createServer(function(req, res) {

}).listen(process.env.PORT || 5265, process.env.IP || '0.0.0.0');

process.on('exit', function() {
process.on('SIGHUP', shutdown);
process.on('SIGINT', shutdown);
process.on('SIGQUIT', shutdown);
process.on('SIGTERM', shutdown);
process.on('SIGTSTP', shutdown);
function shutdown() {
mlsDb.close();
ociDb.close();
uwlDb.close();
ownDb.close();
});
console.log("");
console.log("Closed databases and exiting now");
process.exit(0)
}

console.log('Running at port:', process.env.PORT || 5265);
18 changes: 16 additions & 2 deletions uwl_cells-cleanup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const sqlite3 = require('sqlite3');
const path = require('path');
const util = require('util');
const request = require(path.join(__dirname,'./request.js'));
const mlsDb = new sqlite3.Database(path.join(__dirname, 'mls_cells.sqlite'), sqlite3.OPEN_READONLY);
const ociDb = new sqlite3.Database(path.join(__dirname, 'oci_cells.sqlite'), sqlite3.OPEN_READONLY);
const uwlDb = new sqlite3.Database(path.join(__dirname, 'uwl_cells.sqlite'), sqlite3.OPEN_READWRITE);
Expand Down Expand Up @@ -74,9 +73,24 @@ uwlDb.each("SELECT mcc, mnc, lac, cellid FROM cells", function(err, uwlRow) {
}
});

process.on('exit', function() {
process.on('SIGHUP', shutdown);
process.on('SIGINT', shutdown);
process.on('SIGQUIT', shutdown);
process.on('SIGTERM', shutdown);
process.on('SIGTSTP', shutdown);
function shutdown() {
mlsDb.close();
ociDb.close();
uwlDb.close();
console.log("");
console.log("Closed databases and exiting now")
process.exit(0);
}

process.on('beforeExit', function() {
mlsDb.close();
ociDb.close();
uwlDb.close();
console.log(util.format('Processed entries: %d', numProcessedEntries));
process.exit(0);
});

0 comments on commit e00e4cd

Please sign in to comment.