<commit_before>"""
sentry.tasks.store
~~~~~~~~~~~~~~~~~~

:copyright: (c) 2010-2014 by the Sentry Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""

from __future__ import absolute_import

from django.conf import settings

from sentry.tasks.base import instrumented_task


@instrumented_task(
    name='sentry.tasks.store.preprocess_event',
    queue='events')
def preprocess_event(cache_key=None, data=None, **kwargs):
    from sentry.app import cache
    from sentry.tasks.fetch_source import expand_javascript_source

    if cache_key:
        data = cache.get(cache_key)

    if data is None:
        return

    logger = preprocess_event.get_logger()

    try:
        if settings.SENTRY_SCRAPE_JAVASCRIPT_CONTEXT and data['platform'] == 'javascript':
            try:
                expand_javascript_source(data)
            except Exception as e:
                logger.exception(u'Error fetching javascript source: %r [%s]', data['event_id'], e)
            cache.set(cache_key, data, 3600)
    finally:
        if cache_key:
            data = None<commit_msg>Only re-set cache on success<commit_after>"""
sentry.tasks.store
~~~~~~~~~~~~~~~~~~

:copyright: (c) 2010-2014 by the Sentry Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""

from __future__ import absolute_import

from django.conf import settings

from sentry.tasks.base import instrumented_task


@instrumented_task(
    name='sentry.tasks.store.preprocess_event',
    queue='events')
def preprocess_event(cache_key=None, data=None, **kwargs):
    from sentry.app import cache
    from sentry.tasks.fetch_source import expand_javascript_source

    if cache_key:
        data = cache.get(cache_key)

    if data is None:
        return

    logger = preprocess_event.get_logger()

    try:
        if settings.SENTRY_SCRAPE_JAVASCRIPT_CONTEXT and data['platform'] == 'javascript':
            try:
                expand_javascript_source(data)
            except Exception as e:
                logger.exception(u'Error fetching javascript source: %r [%s]', data['event_id'], e)
            else:
                cache.set(cache_key, data, 3600)
    finally:
        if cache_key:
            data = None
{'fraction_non_alphanumeric': 0.10493552690084482, 'fraction_numerical': 0.01067140951534015, 'mean_word_length': 3.0106951871657754, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2612481', 'n_tokens_mistral': 696, 'n_tokens_neox': 654, 'n_words': 178}