コード例 #1
0
    def wrapped(func):
        @wraps(func)
        def _wrapped(*args, **kwargs):
            # TODO(dcramer): we want to tag a transaction ID, but overriding
            # the base on app.task seems to cause problems w/ Celery internals
            transaction_id = kwargs.pop('__transaction_id', None)

            key = 'jobs.duration'
            if stat_suffix:
                instance = '{}.{}'.format(name, stat_suffix(*args, **kwargs))
            else:
                instance = name
            Raven.tags_context({
                'task_name': name,
                'transaction_id': transaction_id,
            })
            with metrics.timer(key, instance=instance), \
                    track_memory_usage('jobs.memory_change', instance=instance):
                try:
                    result = func(*args, **kwargs)
                finally:
                    Raven.context.clear()
            return result

        return app.task(name=name, **kwargs)(_wrapped)
コード例 #2
0
    def wrapped(func):
        @wraps(func)
        def _wrapped(*args, **kwargs):
            # TODO(dcramer): we want to tag a transaction ID, but overriding
            # the base on app.task seems to cause problems w/ Celery internals
            transaction_id = kwargs.pop("__transaction_id", None)

            key = "jobs.duration"
            if stat_suffix:
                instance = f"{name}.{stat_suffix(*args, **kwargs)}"
            else:
                instance = name

            with configure_scope() as scope:
                scope.set_tag("task_name", name)
                scope.set_tag("transaction_id", transaction_id)

            with metrics.timer(key, instance=instance), track_memory_usage(
                    "jobs.memory_change", instance=instance):
                result = func(*args, **kwargs)

            return result

        # We never use result backends in Celery. Leaving `trail=True` means that if we schedule
        # many tasks from a parent task, each task leaks memory. This can lead to the scheduler
        # being OOM killed.
        kwargs["trail"] = False
        return app.task(name=name, **kwargs)(_wrapped)
コード例 #3
0
ファイル: base.py プロジェクト: DZTPY/sentry
 def wrapped(func):
     @wraps(func)
     def _wrapped(*args, **kwargs):
         key = 'jobs.duration.{name}'.format(name=name)
         if stat_suffix:
             key += '.{key}'.format(key=stat_suffix(*args, **kwargs))
         with metrics.timer(key):
             result = func(*args, **kwargs)
         return result
     return app.task(name=name, **kwargs)(_wrapped)
コード例 #4
0
    def wrapped(func):
        @wraps(func)
        def _wrapped(*args, **kwargs):
            key = 'jobs.duration.{name}'.format(name=name)
            if stat_suffix:
                key += '.{key}'.format(key=stat_suffix(*args, **kwargs))
            with metrics.timer(key):
                result = func(*args, **kwargs)
            return result

        return app.task(name=name, **kwargs)(_wrapped)
コード例 #5
0
ファイル: base.py プロジェクト: carriercomm/sentry-1
 def wrapped(func):
     @wraps(func)
     def _wrapped(*args, **kwargs):
         key = 'jobs.duration'
         if stat_suffix:
             instance = '{}.{}'.format(name, stat_suffix(*args, **kwargs))
         else:
             instance = name
         with metrics.timer(key, instance=instance):
             result = func(*args, **kwargs)
         return result
     return app.task(name=name, **kwargs)(_wrapped)
コード例 #6
0
    def wrapped(func):
        @wraps(func)
        def _wrapped(*args, **kwargs):
            key = 'jobs.duration'
            if stat_suffix:
                instance = '{}.{}'.format(name, stat_suffix(*args, **kwargs))
            else:
                instance = name
            with metrics.timer(key, instance=instance):
                result = func(*args, **kwargs)
            return result

        return app.task(name=name, **kwargs)(_wrapped)
コード例 #7
0
ファイル: base.py プロジェクト: haojiang1/sentry
 def wrapped(func):
     @wraps(func)
     def _wrapped(*args, **kwargs):
         key = 'jobs.duration'
         if stat_suffix:
             instance = '{}.{}'.format(name, stat_suffix(*args, **kwargs))
         else:
             instance = name
         Raven.tags_context({'task_name': name})
         with metrics.timer(key, instance=instance):
             try:
                 result = func(*args, **kwargs)
             finally:
                 Raven.context.clear()
         return result
     return app.task(name=name, **kwargs)(_wrapped)
コード例 #8
0
    def wrapped(func):
        @wraps(func)
        def _wrapped(*args, **kwargs):
            key = 'jobs.duration'
            if stat_suffix:
                instance = '{}.{}'.format(name, stat_suffix(*args, **kwargs))
            else:
                instance = name
            Raven.tags_context({'task_name': name})
            with metrics.timer(key, instance=instance), \
                    track_memory_usage('jobs.memory_change', instance=instance):
                try:
                    result = func(*args, **kwargs)
                finally:
                    Raven.context.clear()
            return result

        return app.task(name=name, **kwargs)(_wrapped)
コード例 #9
0
ファイル: base.py プロジェクト: zsh2938/sentry
 def wrapped(func):
     @wraps(func)
     def _wrapped(*args, **kwargs):
         key = 'jobs.duration'
         if stat_suffix:
             instance = '{}.{}'.format(name, stat_suffix(*args, **kwargs))
         else:
             instance = name
         Raven.tags_context({'task_name': name})
         with metrics.timer(key, instance=instance), \
                 track_memory_usage('jobs.memory_change', instance=instance):
             try:
                 return func(*args, **kwargs)
             except SoftTimeLimitExceeded as error:
                 Raven.context.merge({
                     'fingerprint': [type(error).__name__, instance],
                 })
                 raise
             finally:
                 Raven.context.clear()
     return app.task(name=name, **kwargs)(_wrapped)
コード例 #10
0
ファイル: base.py プロジェクト: zhouhuiquan/sentry
    def wrapped(func):
        @wraps(func)
        def _wrapped(*args, **kwargs):
            # TODO(dcramer): we want to tag a transaction ID, but overriding
            # the base on app.task seems to cause problems w/ Celery internals
            transaction_id = kwargs.pop('__transaction_id', None)

            key = 'jobs.duration'
            if stat_suffix:
                instance = u'{}.{}'.format(name, stat_suffix(*args, **kwargs))
            else:
                instance = name

            with push_scope() as scope:
                scope.set_tag('task_name', name)
                scope.set_tag('transaction_id', transaction_id)

                with metrics.timer(key, instance=instance), \
                        track_memory_usage('jobs.memory_change', instance=instance):
                    result = func(*args, **kwargs)
            return result

        return app.task(name=name, **kwargs)(_wrapped)
コード例 #11
0
ファイル: base.py プロジェクト: pasala91/test
    def wrapped(func):
        @wraps(func)
        def _wrapped(*args, **kwargs):
            # TODO(dcramer): we want to tag a transaction ID, but overriding
            # the base on app.task seems to cause problems w/ Celery internals
            transaction_id = kwargs.pop("__transaction_id", None)

            key = "jobs.duration"
            if stat_suffix:
                instance = f"{name}.{stat_suffix(*args, **kwargs)}"
            else:
                instance = name

            with configure_scope() as scope:
                scope.set_tag("task_name", name)
                scope.set_tag("transaction_id", transaction_id)

            with metrics.timer(key, instance=instance), track_memory_usage(
                    "jobs.memory_change", instance=instance):
                result = func(*args, **kwargs)

            return result

        return app.task(name=name, **kwargs)(_wrapped)