Allow specifying SQLAlchemy engine options in universe_wsgi.ini

For example you can do:

database_connection = postgres:///galaxy_test
database_engine_option_echo = true
database_engine_option_echo_pool = true
database_engine_option_pool_size = 30

To increase the pool size to 30 and turn on SQL and Pool debug echoing
This commit is contained in:
James Taylor
2008-01-09 00:42:27 +00:00
parent 9bd4ab86a3
commit 067abf55dc
3 changed files with 43 additions and 12 deletions
+8 -7
View File
@@ -16,15 +16,16 @@ class UniverseApplication( object ):
#Set up datatypes registry
self.datatypes_registry = galaxy.datatypes.registry.Registry(datatypes=self.config.datatypes, sniff_order=self.config.sniff_order)
galaxy.model.set_datatypes_registry(self.datatypes_registry)
# Connect up the object model
# Determine the database url
if self.config.database_connection:
self.model = galaxy.model.mapping.init( self.config.file_path,
self.config.database_connection,
create_tables = True )
db_url = self.config.database_connection
else:
self.model = galaxy.model.mapping.init( self.config.file_path,
"sqlite://%s?isolation_level=IMMEDIATE" % self.config.database,
create_tables = True )
db_url = "sqlite://%s?isolation_level=IMMEDIATE" % self.config.database
# Setup the database engine and ORM
self.model = galaxy.model.mapping.init( self.config.file_path,
db_url,
self.config.database_engine_options,
create_tables = True )
# Initialize the tools
self.toolbox = tools.ToolBox( self.config.tool_config, self.config.tool_path, self )
#Load datatype converters
+30
View File
@@ -6,6 +6,7 @@ import sys, os
import logging, logging.config
from optparse import OptionParser
import ConfigParser
from galaxy.util import string_as_bool
log = logging.getLogger( __name__ )
@@ -23,8 +24,11 @@ class Configuration( object ):
self.config_dict = kwargs
self.root = kwargs.get( 'root_dir', '.' )
self.enable_beta_features = kwargs.get( "enable_beta_features", False )
# Database related configuration
self.database = resolve_path( kwargs.get( "database_file", "database/universe.d" ), self.root )
self.database_connection = kwargs.get( "database_connection", False )
self.database_engine_options = get_database_engine_options( kwargs )
# Where dataset files are stored
self.file_path = resolve_path( kwargs.get( "file_path", "database/files" ), self.root )
self.new_file_path = resolve_path( kwargs.get( "new_file_path", "database/tmp" ), self.root )
self.tool_path = resolve_path( kwargs.get( "tool_path", "tools" ), self.root )
@@ -85,6 +89,32 @@ class Configuration( object ):
if not os.path.isfile(path):
raise ConfigurationError("File not found: %s" % path )
def get_database_engine_options( kwargs ):
"""
Allow options for the SQLAlchemy database engine to be passed by using
the prefix "database_engine_option_".
"""
conversions = {
'convert_unicode': string_as_bool,
'pool_timeout': int,
'echo': string_as_bool,
'echo_pool': string_as_bool,
'pool_recycle': int,
'pool_size': int,
'max_overflow': int,
'pool_threadlocal': string_as_bool
}
prefix = "database_engine_option_"
prefix_len = len( prefix )
rval = {}
for key, value in kwargs.iteritems():
if key.startswith( prefix ):
key = key[prefix_len:]
if key in conversions:
value = conversions[key](value)
rval[ key ] = value
return rval
def configure_logging( config ):
"""
Allow some basic logging configuration to be read from the cherrpy
+5 -5
View File
@@ -262,9 +262,8 @@ def db_next_hid( self ):
History._next_hid = db_next_hid
def init( file_path, url, **kwargs ):
def init( file_path, url, engine_options, create_tables=False ):
"""Connect mappings to the database"""
create_tables = kwargs.pop( 'create_tables', False )
# Connect dataset to the file path
Dataset.file_path = file_path
# MySQL hacking, doesn't support passive defaults for anything but TIMESTAMP
@@ -274,7 +273,7 @@ def init( file_path, url, **kwargs ):
table.columns['create_time'].type = TIMESTAMP()
if table.columns.has_key( "update_time" ):
table.columns['update_time'].type = TIMESTAMP()
metadata.connect( url, **kwargs )
metadata.connect( url, **engine_options )
# Connect the metadata to the database.
elif url.startswith( "postgresql:///" ):
import psycopg
@@ -290,9 +289,10 @@ def init( file_path, url, **kwargs ):
metadata.connect( engine )
except:
log.exception( "error connecting to database using connection: '%s'." % url )
metadata.connect( url, **kwargs )
metadata.connect( url, **engine_options )
else:
metadata.connect( url, **kwargs )
engine = create_engine( url, **engine_options )
metadata.connect( engine )
## metadata.engine.echo = True
# Create tables if needed
if create_tables: