def example(): d = txmongo.MongoConnectionPool() d.addCallback(insertData) d.addCallback(processResult) d.addErrback(log.err) d.addCallback(finish) return d
def _getConnection(self): if self._connection: return self._connection else: if self.pool: return txmongo.MongoConnectionPool() else: return txmongo.MongoConnection()
def test_MongoConnectionPool(self): # MongoConnectionPool returns deferred, which gets MongoAPI conn = txmongo.MongoConnectionPool(mongo_host, mongo_port, pool_size=2) self.assertEqual(isinstance(conn, defer.Deferred), True) rapi = yield conn self.assertEqual(isinstance(rapi, txmongo.MongoAPI), True) disconnected = yield rapi.disconnect() self.assertEqual(disconnected, True)
def get_mongo(cls): sectionkey = cls.__configsection__ if not sectionkey in cls.__mongo__: CFG = cls._get_config() mongo = yield txmongo.MongoConnectionPool(CFG.host, int(CFG.port), pool_size=CFG.pool_size) cls.__mongo__[sectionkey] = mongo defer.returnValue(cls.__mongo__[sectionkey])
def getConnection(connectionString=''): if not connectionString: connectionString = cfg.database.connectionString parts = connectionString.split(':') scheme = parts[0] if scheme == 'mongo': # XXX take all these parameters from the connection string + query # params deferred = txmongo.MongoConnectionPool(host="localhost", port=27017, reconnect=True, pool_size=5) return deferred
def getConnection(): """ """ d = txmongo.MongoConnectionPool() d.addErrback(log.msg) return d
#!/usr/bin/env python # encoding: utf-8 __author__ = 'sunny' from twisted.internet import reactor from collector_conf import MONGO_HOST, MONGO_NAME, MONGO_PORT, DB_POOL_SIZE, MONGO_USER, MONGO_PASS from collector_conf import LOG_LEVEL, LOG_FILENAME from collector_app import do_collect_app import logging #from pymongo import MongoClient import txmongo if __name__ == '__main__': LOG_FORMAT = '%(asctime)-15s %(levelname)s %(funcName)s %(message)s' logging.basicConfig(level=LOG_LEVEL, format=LOG_FORMAT, filename=LOG_FILENAME, filenode="a") client = txmongo.MongoConnectionPool(host=MONGO_HOST, port=MONGO_PORT,pool_size=DB_POOL_SIZE) #client = txmongo.MongoConnection(host=MONGO_HOST, port=MONGO_PORT) client[MONGO_NAME].authenticate(MONGO_USER, MONGO_PASS) db = client[MONGO_NAME] reactor.callWhenRunning(do_collect_app, db) reactor.run() # db.authenticate(MONGO_USER, MONGO_PASS) #do_collect_app(db)
def getConnection(): print "getting connection..." return txmongo.MongoConnectionPool()