##// END OF EJS Templates
metrics: expose response code to logs
metrics: expose response code to logs

File last commit:

r4817:753f56fc default
r4820:bfc036f6 default
Show More
__init__.py
84 lines | 2.8 KiB | text/x-python | PythonLexer
project: added all source files and assets
r1 # -*- coding: utf-8 -*-
code: update copyrights to 2020
r4306 # Copyright (C) 2010-2020 RhodeCode GmbH
project: added all source files and assets
r1 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
import socket
import logging
import rhodecode
celery: celery 4.X support. Fixes #4169...
r2359 from zope.cachedescriptors.property import Lazy as LazyProperty
from rhodecode.lib.celerylib.loader import (
celery_app, RequestContextTask, get_logger)
metrics: added new statsd client and enabled new metrics on app
r4792 from rhodecode.lib.statsd_client import StatsdClient
project: added all source files and assets
r1
celery: celery 4.X support. Fixes #4169...
r2359 async_task = celery_app.task
project: added all source files and assets
r1
log = logging.getLogger(__name__)
class ResultWrapper(object):
def __init__(self, task):
self.task = task
@LazyProperty
def result(self):
return self.task
def run_task(task, *args, **kwargs):
metrics: added new statsd client and enabled new metrics on app
r4792 log.debug('Got task `%s` for execution, celery mode enabled:%s', task, rhodecode.CELERY_ENABLED)
celerylib: fixed broken tasks for auto-update
r4735 if task is None:
raise ValueError('Got non-existing task for execution')
metrics: added new statsd client and enabled new metrics on app
r4792 exec_mode = 'sync'
celery: fixed error when celery was disabled
r4817 t = None
dan
celery: fixed bug where celery was not running
r265 if rhodecode.CELERY_ENABLED:
project: added all source files and assets
r1 try:
t = task.apply_async(args=args, kwargs=kwargs)
celery: celery 4.X support. Fixes #4169...
r2359 log.debug('executing task %s:%s in async mode', t.task_id, task)
metrics: added new statsd client and enabled new metrics on app
r4792 exec_mode = 'async'
project: added all source files and assets
r1 except socket.error as e:
if isinstance(e, IOError) and e.errno == 111:
celery: improve logging of failed async execution.
r2412 log.error('Unable to connect to celeryd `%s`. Sync execution', e)
project: added all source files and assets
r1 else:
dan
celery: log exception in the event of unknown IOError
r266 log.exception("Exception while connecting to celeryd.")
project: added all source files and assets
r1 except KeyError as e:
celery: improve logging of failed async execution.
r2412 log.error('Unable to connect to celeryd `%s`. Sync execution', e)
project: added all source files and assets
r1 except Exception as e:
log.exception(
"Exception while trying to run task asynchronous. "
"Fallback to sync execution.")
dan
celery: set global CELERY_ENABLED on any connection error
r315
dan
celery: fixed bug where celery was not running
r265 else:
celery: celery 4.X support. Fixes #4169...
r2359 log.debug('executing task %s:%s in sync mode', 'TASK', task)
project: added all source files and assets
r1
metrics: fixed celery task names, fixed hiistogram type metrics, client small fixes
r4807 statsd = StatsdClient.statsd
metrics: added new statsd client and enabled new metrics on app
r4792 if statsd:
metrics: fixed celery task names, fixed hiistogram type metrics, client small fixes
r4807 task_repr = getattr(task, 'name', task)
metrics: use prom metrics, and added some additional metrics
r4803 statsd.incr('rhodecode_celery_task_total', tags=[
metrics: fixed celery task names, fixed hiistogram type metrics, client small fixes
r4807 'task:{}'.format(task_repr),
metrics: added new statsd client and enabled new metrics on app
r4792 'mode:{}'.format(exec_mode)
])
metrics: fixed celery task names, fixed hiistogram type metrics, client small fixes
r4807
# we got async task, return it after statsd call
if t:
return t
celery: celery 4.X support. Fixes #4169...
r2359 return ResultWrapper(task(*args, **kwargs))