<commit_before>"""
Defines asynchronous celery task for sending email notification (through edx-ace)
pertaining to new discussion forum comments.
"""


import logging

from celery import shared_task
from celery_utils.logged_task import LoggedTask
from django.conf import settings  # lint-amnesty, pylint: disable=unused-import
from django.contrib.auth.models import User  # lint-amnesty, pylint: disable=imported-auth-user
from django.contrib.sites.models import Site
from edx_ace import ace
from edx_ace.recipient import Recipient
from edx_ace.utils import date
from edx_django_utils.monitoring import set_code_owner_attribute
from eventtracking import tracker
from opaque_keys.edx.keys import CourseKey
from six.moves.urllib.parse import urljoin

import openedx.core.djangoapps.django_comment_common.comment_client as cc
from common.djangoapps.track import segment
from lms.djangoapps.discussion.django_comment_client.utils import (
    get_accessible_discussion_xblocks_by_course_id,
    permalink
)
from openedx.core.djangoapps.ace_common.message import BaseMessageType
from openedx.core.djangoapps.ace_common.template_context import get_base_template_context
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
from openedx.core.djangoapps.django_comment_common.models import DiscussionsIdMapping
from openedx.core.lib.celery.task_utils import emulate_http_request

log = logging.getLogger(__name__)


DEFAULT_LANGUAGE = 'en'


@shared_task(base=LoggedTask)
@set_code_owner_attribute
def update_discussions_map(context):
    """
    Updates the mapping between discussion_id to discussion block usage key
    for all discussion blocks in the given course.

    context is a dict that contains:
        course_id (string): identifier of the course
    """
    course_key = CourseKey.from_string(context['course_id'])
    discussion_blocks = get_accessible_discussion_xblocks_by_course_id(course_key, include_all=True)
    discussions_id_map = {
        discussion_block.discussion_id: str(discussion_block.location)
        for discussion_block in discussion_blocks
    }
    DiscussionsIdMapping.update_mapping(course_key, discussions_id_map)


class ResponseNotification(BaseMessageType):
    pass


@shared_task(base=LoggedTask)<commit_msg>feat: mark forum response notifications transactional<commit_after>"""
Defines asynchronous celery task for sending email notification (through edx-ace)
pertaining to new discussion forum comments.
"""


import logging

from celery import shared_task
from celery_utils.logged_task import LoggedTask
from django.conf import settings  # lint-amnesty, pylint: disable=unused-import
from django.contrib.auth.models import User  # lint-amnesty, pylint: disable=imported-auth-user
from django.contrib.sites.models import Site
from edx_ace import ace
from edx_ace.recipient import Recipient
from edx_ace.utils import date
from edx_django_utils.monitoring import set_code_owner_attribute
from eventtracking import tracker
from opaque_keys.edx.keys import CourseKey
from six.moves.urllib.parse import urljoin

import openedx.core.djangoapps.django_comment_common.comment_client as cc
from common.djangoapps.track import segment
from lms.djangoapps.discussion.django_comment_client.utils import (
    get_accessible_discussion_xblocks_by_course_id,
    permalink
)
from openedx.core.djangoapps.ace_common.message import BaseMessageType
from openedx.core.djangoapps.ace_common.template_context import get_base_template_context
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
from openedx.core.djangoapps.django_comment_common.models import DiscussionsIdMapping
from openedx.core.lib.celery.task_utils import emulate_http_request

log = logging.getLogger(__name__)


DEFAULT_LANGUAGE = 'en'


@shared_task(base=LoggedTask)
@set_code_owner_attribute
def update_discussions_map(context):
    """
    Updates the mapping between discussion_id to discussion block usage key
    for all discussion blocks in the given course.

    context is a dict that contains:
        course_id (string): identifier of the course
    """
    course_key = CourseKey.from_string(context['course_id'])
    discussion_blocks = get_accessible_discussion_xblocks_by_course_id(course_key, include_all=True)
    discussions_id_map = {
        discussion_block.discussion_id: str(discussion_block.location)
        for discussion_block in discussion_blocks
    }
    DiscussionsIdMapping.update_mapping(course_key, discussions_id_map)


class ResponseNotification(BaseMessageType):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.options['transactional'] = True


@shared_task(base=LoggedTask)
{'fraction_non_alphanumeric': 0.06193001060445387, 'fraction_numerical': 0.0, 'mean_word_length': 5.87463556851312, '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': '5430644', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1329, 'n_words': 335}