Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const opts = {
max: 10,
min: 2,
maxWaitingClients: 2,
testOnBorrow: true,
acquireTimeoutMillis: 100,
fifo: true,
priorityRange: 5,
autostart: false,
evictionRunIntervalMillis: 200,
numTestsPerRun: 3,
softIdleTimeoutMillis: 100,
idleTimeoutMillis: 5000
};
const pool = genericPool.createPool(factory, opts);
pool.start();
pool.use((conn: Connection) => 'test')
.then((result: string) => { });
pool.acquire()
.then((conn: Connection) => {
console.log(pool.isBorrowedResource(conn)); // => true
return pool.release(conn);
}).then(() => {
return pool.acquire(5);
}).then((conn: Connection) => {
return pool.destroy(conn);
}).then(() => {
return pool.clear();
//
// The pool should be used for WATCH/MULTI/EXEC transactions
//
const factory = {
create() {
return Promise.resolve(createClient());
},
destroy(client) {
client.quit();
return Promise.resolve();
}
};
const opts = { min: 1, max: 10 };
this.pool = genericPool.createPool(factory, opts);
}
}
} 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);
},
return function Actor(configStr) {
// if we can't create a new actor, throw early rather than in the actor pool
new Valhalla(configStr);
const actorPool = genericPool.createPool(actorFactory, opts);
function actorMethodFactory(methodName) {
return function(request, cb) {
if (!request || !cb) throw new Error('method must be called with string and callback');
actorPool.acquire().then(function(actor) {
actorPool.on('factoryCreateError', function(err) {
return cb(err);
});
actor[methodName](request, function(err, result) {
actorPool.release(actor);
return cb(err, result);
});
});
}
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
});
}