Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
} else {
return self.pool.write.release(client);
}
},
acquire: function(callback, priority, queryType) {
if (queryType === 'SELECT') {
self.pool.read.acquire(callback, priority);
} else {
self.pool.write.acquire(callback, priority);
}
},
drain: function() {
self.pool.read.drain();
self.pool.write.drain();
},
read: Pooling.Pool({
name: 'sequelize-connection-read',
create: function(callback) {
if (reads >= config.replication.read.length) {
reads = 0;
}
// Simple round robin config
self.$connect(config.replication.read[reads++]).tap(function (connection) {
connection.queryType = 'read';
}).nodeify(function (err, connection) {
callback(err, connection); // For some reason this is needed, else generic-pool things err is a connection or some shit
});
},
destroy: function(connection) {
self.$disconnect(connection);
},
validate: config.pool.validate,
// Known SRS values
var SRS = {
'WGS84': '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs',
'900913': '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 ' +
'+y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over'
};
// on object of locks for concurrent downloads
var downloads = {};
// object for tracking logging on downloads
var download_log_interval = null;
// last download count, in order to limit logging barf
var download_last_count = 0;
var pool = require('generic-pool').Pool({
create: function(callback) {
callback(null, {});
},
destroy: function(obj) {
obj = undefined;
},
max: 10
});
function download(url, options, callback) {
if (env == 'development') {
if (!download_log_interval) {
download_log_interval = setInterval(function() {
var in_use = Object.keys(downloads);
if (in_use.length > 0 && (download_last_count !== in_use.length)) {
function Pool (path, args, options, settings) {
_.defaults(settings, {
name: 'fork-pool',
size: require('os').cpus().length,
log: false,
timeout: 30000,
debug: false,
debugPort: process.debugPort // Default debugging port for the main process. Skip from here.
});
//
this.pool = generic.Pool({
settings: settings,
name: settings.name,
create: function (callback) {
var debugArgIdx = process.execArgv.indexOf('--debug');
if (debugArgIdx !== -1) {
// Remove debugging from process before forking
process.execArgv.splice(debugArgIdx, 1);
}
if (this.settings.debug) {
// Optionally set an unused port number if you want to debug the children.
// This only works if idle processes stay alive (long timeout), or you will run out of ports eventually.
process.execArgv.push('--debug=' + (++this.settings.debugPort));
}
var childNode = childProcess.fork(path, args, options);
callback(null, childNode);
},
var createPool = function(name, options) {
return connectionPooler.Pool({
name: name,
create: function(callback) {
var host = config.get('muxamp:db:host'),
database = config.get('muxamp:db:name'),
user = config.get('muxamp:db:user'),
password = config.get('muxamp:db:password');
var status = 'Host: ' + host + ', DB: ' + database + ', user: ' + user + ', password: ' + (password ? '***' : undefined);
if (!(host && database && user && password)) {
throw new Error('Database configuration not fully specified. ' + status);
}
var params = _.extend({}, options, {
host: host,
database: database,
user: user,
password: password
});
constructor (options, max, min, idleTimeoutMillis) {
this.pool = gp.Pool({
name: 'rethinkdb',
create: (callback) => {
return r.connect(options, callback);
},
destroy: (connection) => {
return connection.close();
},
validate: function(connection) {
return connection.isOpen();
},
log: false,
min: min || 2,
max: max || 10,
idleTimeoutMillis: idleTimeoutMillis || 30000
});
}
done(err, connection)
}, self.config.replication.write)
},
destroy: function(client) {
disconnect.call(self, client)
},
validate: self.poolCfg.validate,
max: self.poolCfg.maxConnections,
min: self.poolCfg.minConnections,
idleTimeoutMillis: self.poolCfg.maxIdleTime
})
};
} else if (this.poolCfg) {
//the user has requested pooling, so create our connection pool
this.pool = Pooling.Pool({
name: 'sequelize-mariadb',
create: function (done) {
connect.call(self, done)
},
destroy: function(client) {
disconnect.call(self, client)
},
max: self.poolCfg.maxConnections,
min: self.poolCfg.minConnections,
validate: self.poolCfg.validate,
idleTimeoutMillis: self.poolCfg.maxIdleTime
})
}
this.onProcessExit = function () {
//be nice & close our connections on exit
function createAccountDBPool()
{
return generic_pool.Pool({
name: 'mongodb-account',
create: function(createCallback) {
env_config.loadConfig().then(function(envSettings) {
mongodb.MongoClient.connect(
envSettings.ACCOUNT_DB_URI,
function (err, db) {
createCallback(null, db);
}
);
});
},
destroy: function(db) { db.close(); },
max: MAX_DB_CONNECTIONS,
idleTimeoutMillis : DB_TIMEOUT
});
}
if (connection) {
connection.queryType = 'read'
}
done(err, connection)
}, config);
},
destroy: function(client) {
disconnect.call(self, client)
},
validate: self.poolCfg.validate,
max: self.poolCfg.maxConnections,
min: self.poolCfg.minConnections,
idleTimeoutMillis: self.poolCfg.maxIdleTime
}),
write: Pooling.Pool({
name: 'sequelize-write',
create: function (done) {
connect.call(self, function (err, connection) {
if (connection) {
connection.queryType = 'read'
}
done(err, connection)
}, self.config.replication.write);
},
destroy: function(client) {
disconnect.call(self, client)
},
validate: self.poolCfg.validate,
max: self.poolCfg.maxConnections,
min: self.poolCfg.minConnections,
module.exports = function factory(settings) {
return new Pool(settings);
};
connection.removeAllListeners()
connection.on('error', function () {})
connection.end()
},
log: options.log,
idleTimeoutMillis: options.idleTimeout,
reapIntervalMillis: options.reapInterval,
}
if (options.hasOwnProperty('refreshIdle')) {
poolOpts.refreshIdle = options.refreshIdle
}
this._pool = new GenericPool(poolOpts)
this._cancelledQueries = []
var resetSteps = []
if (adapter.reset) resetSteps.unshift(adapter.reset)
if (options.reset) resetSteps.unshift(options.reset)
this.adapter = adapter
this._reset = chain(resetSteps)
this._shouldDestroyConnection = function (err) {
if (err instanceof CancelledQueryError) {
return false
}
return options.shouldDestroyConnection ? options.shouldDestroyConnection(err) : true
}
var self = this