##// END OF EJS Templates
make rhodecode reuse current session when not running on celery
marcink -
r559:bc4633a4 default
parent child Browse files
Show More
@@ -13,29 +13,34 b' import traceback'
13
13
14 try:
14 try:
15 from celeryconfig import PYLONS_CONFIG as config
15 from celeryconfig import PYLONS_CONFIG as config
16 celery_on = True
16 except ImportError:
17 except ImportError:
17 #if celeryconfig is not present let's just load our pylons
18 #if celeryconfig is not present let's just load our pylons
18 #config instead
19 #config instead
19 from pylons import config
20 from pylons import config
21 celery_on = False
20
22
21
23
22 __all__ = ['whoosh_index', 'get_commits_stats',
24 __all__ = ['whoosh_index', 'get_commits_stats',
23 'reset_user_password', 'send_email']
25 'reset_user_password', 'send_email']
24
26
25 def get_session():
27 def get_session():
28 if celery_on:
26 from sqlalchemy import engine_from_config
29 from sqlalchemy import engine_from_config
27 from sqlalchemy.orm import sessionmaker, scoped_session
30 from sqlalchemy.orm import sessionmaker, scoped_session
28 engine = engine_from_config(dict(config.items('app:main')), 'sqlalchemy.db1.')
31 engine = engine_from_config(dict(config.items('app:main')), 'sqlalchemy.db1.')
29 sa = scoped_session(sessionmaker(bind=engine))
32 sa = scoped_session(sessionmaker(bind=engine))
33 else:
34 #If we don't use celery reuse our current application Session
35 from rhodecode.model.meta import Session
36 sa = Session
37
30 return sa
38 return sa
31
39
32 def get_hg_settings():
40 def get_hg_settings():
33 from rhodecode.model.db import RhodeCodeSettings
41 from rhodecode.model.db import RhodeCodeSettings
34 try:
35 sa = get_session()
42 sa = get_session()
36 ret = sa.query(RhodeCodeSettings).all()
43 ret = sa.query(RhodeCodeSettings).all()
37 finally:
38 sa.remove()
39
44
40 if not ret:
45 if not ret:
41 raise Exception('Could not get application settings !')
46 raise Exception('Could not get application settings !')
@@ -47,11 +52,8 b' def get_hg_settings():'
47
52
48 def get_hg_ui_settings():
53 def get_hg_ui_settings():
49 from rhodecode.model.db import RhodeCodeUi
54 from rhodecode.model.db import RhodeCodeUi
50 try:
51 sa = get_session()
55 sa = get_session()
52 ret = sa.query(RhodeCodeUi).all()
56 ret = sa.query(RhodeCodeUi).all()
53 finally:
54 sa.remove()
55
57
56 if not ret:
58 if not ret:
57 raise Exception('Could not get application ui settings !')
59 raise Exception('Could not get application ui settings !')
General Comments 0
You need to be logged in to leave comments. Login now