<commit_before># -*- coding: utf-8 -*-
import json
import requests
from celery import shared_task
from django.conf import settings
from django.core.cache import cache
from django.core.serializers.json import DjangoJSONEncoder
from simplejson import JSONDecodeError

from .models import Notification
from .serializers import NotificationSerializer


CACHE_KEY = 'cla_backend.notifications.task.notifications'


@shared_task(default_retry_delay=1, max_retries=12)
def send_notifications():
    data = {
        'notifications': NotificationSerializer(
            Notification.objects.live(),
            many=True).data
    }
    cache.set(CACHE_KEY, data['notifications'])

    response = requests.post(
        '%s:%s/admin/notifications/' % (settings.FRONTEND_HOST_NAME,
                                        settings.EXPRESS_SERVER_PORT),
        data=json.dumps(data, cls=DjangoJSONEncoder),
        headers={'content-type': 'application/json'}
    )
    try:
        success = response.json()['success']
        assert success is True
    except (JSONDecodeError, AssertionError) as e:
        raise send_notifications.retry(exc=e)
    else:
        return success
<commit_msg>use ValueError<commit_after># -*- coding: utf-8 -*-
import json
import requests
from celery import shared_task
from django.conf import settings
from django.core.cache import cache
from django.core.serializers.json import DjangoJSONEncoder

from .models import Notification
from .serializers import NotificationSerializer


CACHE_KEY = 'cla_backend.notifications.task.notifications'


@shared_task(default_retry_delay=1, max_retries=12)
def send_notifications():
    data = {
        'notifications': NotificationSerializer(
            Notification.objects.live(),
            many=True).data
    }
    cache.set(CACHE_KEY, data['notifications'])

    response = requests.post(
        '%s:%s/admin/notifications/' % (settings.FRONTEND_HOST_NAME,
                                        settings.EXPRESS_SERVER_PORT),
        data=json.dumps(data, cls=DjangoJSONEncoder),
        headers={'content-type': 'application/json'}
    )
    try:
        success = response.json()['success']
        assert success is True
    except (ValueError, AssertionError) as e:
        raise send_notifications.retry(exc=e)
    else:
        return success

{'fraction_non_alphanumeric': 0.09634408602150538, 'fraction_numerical': 0.0034408602150537634, 'mean_word_length': 3.1535714285714285, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7543669', 'n_tokens_mistral': 639, 'n_tokens_neox': 629, 'n_words': 145}