Show More
@@ -40,7 +40,7 b' from pyramid.threadlocal import get_curr' | |||
|
40 | 40 | import rhodecode |
|
41 | 41 | |
|
42 | 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 | 44 | from rhodecode.lib.ext_json import json |
|
45 | 45 | from rhodecode.lib.pyramid_utils import bootstrap, setup_logging, prepare_request |
|
46 | 46 | from rhodecode.lib.utils2 import str2bool |
@@ -144,6 +144,11 b' def on_preload_parsed(options, **kwargs)' | |||
|
144 | 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 | 152 | @signals.task_success.connect |
|
148 | 153 | def task_success_signal(result, **kwargs): |
|
149 | 154 | meta.Session.commit() |
@@ -227,8 +232,7 b' def maybe_prepare_env(req):' | |||
|
227 | 232 | environ.update({ |
|
228 | 233 | 'PATH_INFO': req.environ['PATH_INFO'], |
|
229 | 234 | 'SCRIPT_NAME': req.environ['SCRIPT_NAME'], |
|
230 | 'HTTP_HOST': | |
|
231 | req.environ.get('HTTP_HOST', req.environ['SERVER_NAME']), | |
|
235 | 'HTTP_HOST':req.environ.get('HTTP_HOST', req.environ['SERVER_NAME']), | |
|
232 | 236 | 'SERVER_NAME': req.environ['SERVER_NAME'], |
|
233 | 237 | 'SERVER_PORT': req.environ['SERVER_PORT'], |
|
234 | 238 | 'wsgi.url_scheme': req.environ['wsgi.url_scheme'], |
@@ -22,6 +22,7 b' import os' | |||
|
22 | 22 | import json |
|
23 | 23 | import logging |
|
24 | 24 | import datetime |
|
25 | import time | |
|
25 | 26 | |
|
26 | 27 | from functools import partial |
|
27 | 28 | |
@@ -30,7 +31,6 b' from celery.result import AsyncResult' | |||
|
30 | 31 | import celery.loaders.base |
|
31 | 32 | import celery.schedules |
|
32 | 33 | |
|
33 | ||
|
34 | 34 | log = logging.getLogger(__name__) |
|
35 | 35 | |
|
36 | 36 | |
@@ -167,3 +167,21 b' def parse_ini_vars(ini_vars):' | |||
|
167 | 167 | key, value = pairs.split('=') |
|
168 | 168 | options[key] = value |
|
169 | 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