aboutsummaryrefslogtreecommitdiff
path: root/rhodecode
diff options
context:
space:
mode:
authorMarcin Kuzminski <marcin@python-works.com>2010-10-07 22:01:51 +0200
committerMarcin Kuzminski <marcin@python-works.com>2010-10-07 22:01:51 +0200
commit156c4c255d7054911a84dfdf3f341e43ee4907de (patch)
tree798f4f65d699b5a5afb569984ccc3e373d580934 /rhodecode
parent4addd5ddf610c45e27df99ebb0d9ed0d71779b43 (diff)
make rhodecode reuse current session when not running on celery
Diffstat (limited to 'rhodecode')
-rw-r--r--rhodecode/lib/celerylib/tasks.py30
1 files changed, 16 insertions, 14 deletions
diff --git a/rhodecode/lib/celerylib/tasks.py b/rhodecode/lib/celerylib/tasks.py
index 56e112a3..bfec292a 100644
--- a/rhodecode/lib/celerylib/tasks.py
+++ b/rhodecode/lib/celerylib/tasks.py
@@ -13,29 +13,34 @@ import traceback
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_settings():
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 !')