Changeset - bc4633a41967
[Not reviewed]
default
0 1 0
Marcin Kuzminski - 15 years ago 2010-10-07 22:01:51
marcin@python-works.com
make rhodecode reuse current session when not running on celery
1 file changed with 8 insertions and 6 deletions:
0 comments (0 inline, 0 general)
rhodecode/lib/celerylib/tasks.py
Show inline comments
 
@@ -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():
 
    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()
 
        
 
    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()
 
        
 
    if not ret:
 
        raise Exception('Could not get application ui settings !')
0 comments (0 inline, 0 general)