diff options
| author | Joshua Harlow <harlowja@yahoo-inc.com> | 2014-06-04 19:28:18 -0700 |
|---|---|---|
| committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2014-06-11 20:12:48 -0700 |
| commit | 231e4c6cf8f57b96ca10d52d07b38d221eba5c21 (patch) | |
| tree | fb3bf4eb1ade52bf004fb059ad3b5d7037e086ea /taskflow/persistence/backends/impl_sqlalchemy.py | |
| parent | 0adf714f3a3f01cfc74780b1a35367fd487eb474 (diff) | |
| download | taskflow-231e4c6cf8f57b96ca10d52d07b38d221eba5c21.tar.gz | |
Remove misc.as_bool as oslo provides an equivalent
There isn't a need to have a misc.as_bool function
anymore now that we have imported the oslo incubator
strutils module since that module provides a function
that does *nearly* the same thing.
Change-Id: I7afe141d5a37c50b0c926144743f9af71db95bbf
Diffstat (limited to 'taskflow/persistence/backends/impl_sqlalchemy.py')
| -rw-r--r-- | taskflow/persistence/backends/impl_sqlalchemy.py | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/taskflow/persistence/backends/impl_sqlalchemy.py b/taskflow/persistence/backends/impl_sqlalchemy.py index 81f053e..26cc4d2 100644 --- a/taskflow/persistence/backends/impl_sqlalchemy.py +++ b/taskflow/persistence/backends/impl_sqlalchemy.py @@ -32,6 +32,7 @@ from sqlalchemy import orm as sa_orm from sqlalchemy import pool as sa_pool from taskflow import exceptions as exc +from taskflow.openstack.common import strutils from taskflow.persistence.backends import base from taskflow.persistence.backends.sqlalchemy import migration from taskflow.persistence.backends.sqlalchemy import models @@ -120,6 +121,18 @@ def _is_db_connection_error(reason): return _in_any(reason, list(MY_SQL_CONN_ERRORS + POSTGRES_CONN_ERRORS)) +def _as_bool(value): + if isinstance(value, bool): + return value + # This is different than strutils, but imho is an acceptable difference. + if value is None: + return False + # NOTE(harlowja): prefer strictness to avoid users getting accustomed + # to passing bad values in and this *just working* (which imho is a bad + # habit to encourage). + return strutils.bool_from_string(value, strict=True) + + def _thread_yield(dbapi_con, con_record): """Ensure other greenthreads get a chance to be executed. @@ -183,8 +196,8 @@ class SQLAlchemyBackend(base.Backend): # all the popping that will happen below. conf = copy.deepcopy(self._conf) engine_args = { - 'echo': misc.as_bool(conf.pop('echo', False)), - 'convert_unicode': misc.as_bool(conf.pop('convert_unicode', True)), + 'echo': _as_bool(conf.pop('echo', False)), + 'convert_unicode': _as_bool(conf.pop('convert_unicode', True)), 'pool_recycle': 3600, } if 'idle_timeout' in conf: @@ -229,13 +242,13 @@ class SQLAlchemyBackend(base.Backend): engine = sa.create_engine(sql_connection, **engine_args) checkin_yield = conf.pop('checkin_yield', eventlet_utils.EVENTLET_AVAILABLE) - if misc.as_bool(checkin_yield): + if _as_bool(checkin_yield): sa.event.listen(engine, 'checkin', _thread_yield) if 'mysql' in e_url.drivername: - if misc.as_bool(conf.pop('checkout_ping', True)): + if _as_bool(conf.pop('checkout_ping', True)): sa.event.listen(engine, 'checkout', _ping_listener) mode = None - if misc.as_bool(conf.pop('mysql_traditional_mode', True)): + if _as_bool(conf.pop('mysql_traditional_mode', True)): mode = 'TRADITIONAL' if 'mysql_sql_mode' in conf: mode = conf.pop('mysql_sql_mode') |
