Show More
@@ -40,7 +40,7 b' from pyramid.threadlocal import get_curr' | |||||
40 | import rhodecode |
|
40 | import rhodecode | |
41 |
|
41 | |||
42 | from rhodecode.lib.auth import AuthUser |
|
42 | from rhodecode.lib.auth import AuthUser | |
43 | from rhodecode.lib.celerylib.utils import get_ini_config, parse_ini_vars |
|
43 | from rhodecode.lib.celerylib.utils import get_ini_config, parse_ini_vars, ping_db | |
44 | from rhodecode.lib.ext_json import json |
|
44 | from rhodecode.lib.ext_json import json | |
45 | from rhodecode.lib.pyramid_utils import bootstrap, setup_logging, prepare_request |
|
45 | from rhodecode.lib.pyramid_utils import bootstrap, setup_logging, prepare_request | |
46 | from rhodecode.lib.utils2 import str2bool |
|
46 | from rhodecode.lib.utils2 import str2bool | |
@@ -144,6 +144,11 b' def on_preload_parsed(options, **kwargs)' | |||||
144 | rhodecode.CELERY_ENABLED = True |
|
144 | rhodecode.CELERY_ENABLED = True | |
145 |
|
145 | |||
146 |
|
146 | |||
|
147 | @signals.task_prerun.connect | |||
|
148 | def task_prerun_signal(task_id, task, args, **kwargs): | |||
|
149 | ping_db() | |||
|
150 | ||||
|
151 | ||||
147 | @signals.task_success.connect |
|
152 | @signals.task_success.connect | |
148 | def task_success_signal(result, **kwargs): |
|
153 | def task_success_signal(result, **kwargs): | |
149 | meta.Session.commit() |
|
154 | meta.Session.commit() | |
@@ -227,8 +232,7 b' def maybe_prepare_env(req):' | |||||
227 | environ.update({ |
|
232 | environ.update({ | |
228 | 'PATH_INFO': req.environ['PATH_INFO'], |
|
233 | 'PATH_INFO': req.environ['PATH_INFO'], | |
229 | 'SCRIPT_NAME': req.environ['SCRIPT_NAME'], |
|
234 | 'SCRIPT_NAME': req.environ['SCRIPT_NAME'], | |
230 | 'HTTP_HOST': |
|
235 | 'HTTP_HOST':req.environ.get('HTTP_HOST', req.environ['SERVER_NAME']), | |
231 | req.environ.get('HTTP_HOST', req.environ['SERVER_NAME']), |
|
|||
232 | 'SERVER_NAME': req.environ['SERVER_NAME'], |
|
236 | 'SERVER_NAME': req.environ['SERVER_NAME'], | |
233 | 'SERVER_PORT': req.environ['SERVER_PORT'], |
|
237 | 'SERVER_PORT': req.environ['SERVER_PORT'], | |
234 | 'wsgi.url_scheme': req.environ['wsgi.url_scheme'], |
|
238 | 'wsgi.url_scheme': req.environ['wsgi.url_scheme'], |
@@ -22,6 +22,7 b' import os' | |||||
22 | import json |
|
22 | import json | |
23 | import logging |
|
23 | import logging | |
24 | import datetime |
|
24 | import datetime | |
|
25 | import time | |||
25 |
|
26 | |||
26 | from functools import partial |
|
27 | from functools import partial | |
27 |
|
28 | |||
@@ -30,7 +31,6 b' from celery.result import AsyncResult' | |||||
30 | import celery.loaders.base |
|
31 | import celery.loaders.base | |
31 | import celery.schedules |
|
32 | import celery.schedules | |
32 |
|
33 | |||
33 |
|
||||
34 | log = logging.getLogger(__name__) |
|
34 | log = logging.getLogger(__name__) | |
35 |
|
35 | |||
36 |
|
36 | |||
@@ -167,3 +167,21 b' def parse_ini_vars(ini_vars):' | |||||
167 | key, value = pairs.split('=') |
|
167 | key, value = pairs.split('=') | |
168 | options[key] = value |
|
168 | options[key] = value | |
169 | return options |
|
169 | return options | |
|
170 | ||||
|
171 | ||||
|
172 | def ping_db(): | |||
|
173 | from rhodecode.model import meta | |||
|
174 | from rhodecode.model.db import DbMigrateVersion | |||
|
175 | log.info('Testing DB connection...') | |||
|
176 | ||||
|
177 | for test in range(10): | |||
|
178 | try: | |||
|
179 | scalar = DbMigrateVersion.query().scalar() | |||
|
180 | log.debug('DB PING %s@%s', scalar, scalar.version) | |||
|
181 | break | |||
|
182 | except Exception: | |||
|
183 | retry = 1 | |||
|
184 | log.debug('DB not ready, next try in %ss', retry) | |||
|
185 | time.sleep(retry) | |||
|
186 | finally: | |||
|
187 | meta.Session.remove() |
General Comments 0
You need to be logged in to leave comments.
Login now