Skip to content
This repository has been archived by the owner on Apr 30, 2022. It is now read-only.

Commit

Permalink
move DB inside handler (for proper teardown)
Browse files Browse the repository at this point in the history
  • Loading branch information
sedenardi committed Dec 21, 2017
1 parent 311264d commit 48a0e53
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

const Feeds = require('./src/Feeds');
const db = require('./src/db')();

const run = function() {
const db = require('./src/db')();
return Feeds.get(db).then((feeds) => {
return feeds.run().then(() => {
return feeds.cleanup();
Expand All @@ -16,9 +16,9 @@ const run = function() {
module.exports = {
handler: (event, context, callback) => {
run().then(() => {
callback();
context.done();
}).catch((err) => {
callback(err);
context.done(err);
});
}
};
1 change: 1 addition & 0 deletions src/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = function() {
return new Promise((resolve, reject) => {
pool.end((err) => {
if (err) { return reject(err); }
console.log('Closing database.');
return resolve();
});
});
Expand Down

0 comments on commit 48a0e53

Please sign in to comment.