Skip to content

Commit

Permalink
added connection pool errors to global event emitter
Browse files Browse the repository at this point in the history
  • Loading branch information
timgit committed Mar 9, 2017
1 parent ce43ceb commit 5c8e6a9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/db.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const EventEmitter = require('events').EventEmitter; //node 0.10 compatibility;
const pg = require('pg');
const Promise = require("bluebird");
const migrations = require('./migrations');
const url = require('url');

class Db {
class Db extends EventEmitter {
constructor(config){
super();

this.config = config;

Expand All @@ -21,6 +23,7 @@ class Db {
max: poolConfig.poolSize
});

this.pool.on('error', error => this.emit('error', error));

function parseConnectionString(connectionString){
const params = url.parse(connectionString);
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class PgBoss extends EventEmitter {
this.config = config;

const db = new Db(config);
db.on('error', error => this.emit('error', error));

// contractor makes sure we have a happy database home for work
this.contractor = new Contractor(db, config);
Expand Down

0 comments on commit 5c8e6a9

Please sign in to comment.