Mercurial > kallithea
diff rhodecode/lib/celerylib/tasks.py @ 559:bc4633a41967
make rhodecode reuse current session when not running on celery
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 07 Oct 2010 22:01:51 +0200 |
parents | 03676d39dd0a |
children | 1a77a0c350f5 |
line wrap: on
line diff
--- a/rhodecode/lib/celerylib/tasks.py Thu Oct 07 19:24:03 2010 +0200 +++ b/rhodecode/lib/celerylib/tasks.py Thu Oct 07 22:01:51 2010 +0200 @@ -13,29 +13,34 @@ try: from celeryconfig import PYLONS_CONFIG as config + celery_on = True except ImportError: #if celeryconfig is not present let's just load our pylons #config instead from pylons import config + celery_on = False __all__ = ['whoosh_index', 'get_commits_stats', 'reset_user_password', 'send_email'] def get_session(): - from sqlalchemy import engine_from_config - from sqlalchemy.orm import sessionmaker, scoped_session - engine = engine_from_config(dict(config.items('app:main')), 'sqlalchemy.db1.') - sa = scoped_session(sessionmaker(bind=engine)) + if celery_on: + from sqlalchemy import engine_from_config + from sqlalchemy.orm import sessionmaker, scoped_session + engine = engine_from_config(dict(config.items('app:main')), 'sqlalchemy.db1.') + sa = scoped_session(sessionmaker(bind=engine)) + else: + #If we don't use celery reuse our current application Session + from rhodecode.model.meta import Session + sa = Session + return sa def get_hg_settings(): from rhodecode.model.db import RhodeCodeSettings - try: - sa = get_session() - ret = sa.query(RhodeCodeSettings).all() - finally: - sa.remove() + sa = get_session() + ret = sa.query(RhodeCodeSettings).all() if not ret: raise Exception('Could not get application settings !') @@ -47,11 +52,8 @@ def get_hg_ui_settings(): from rhodecode.model.db import RhodeCodeUi - try: - sa = get_session() - ret = sa.query(RhodeCodeUi).all() - finally: - sa.remove() + sa = get_session() + ret = sa.query(RhodeCodeUi).all() if not ret: raise Exception('Could not get application ui settings !')