<commit_before>import django_rq
import time
from django import db
from django.conf import settings
from django.core.cache import cache
from django.core.mail import send_mail
from django.template.loader import get_template
from metaci.users.models import User
from metaci.build.models import Build
from metaci.notification.models import RepositoryNotification
from metaci.notification.models import BranchNotification
from metaci.notification.models import PlanNotification
from metaci.notification.models import PlanRepositoryNotification
from metaci.plan.models import PlanRepository


def reset_database_connection():
    db.connection.close()

@django_rq.job('short', timeout=60)
def queue_build_notifications(build_id):
    reset_database_connection()

    build = Build.objects.get(id=build_id)

    status_query = {}

    if build.get_status() in ['queued', 'waiting', 'in_progress']:
        return 'Skipping, build not done yet'
    
    if build.get_status() == 'success':
        status_query['on_success'] = True
    elif build.get_status() == 'fail':
        status_query['on_fail'] = True
    elif build.get_status() == 'error':
        status_query['on_error'] = True
    
    repo_notifications = RepositoryNotification.objects.filter(repo = build.repo, **status_query).values('user__id').distinct()
    branch_notifications = BranchNotification.objects.filter(branch = build.branch, **status_query).values('user__id').distinct()
    plan_notifications = PlanNotification.objects.filter(plan = build.plan, **status_query).values('user__id').distinct()
    planrepository = PlanRepository.objects.filter(plan=build.plan, repo=build.repo)[0]
    planrepository_notifications = PlanRepositoryNotification.objects.filter(planrepository=planrepository, **status_query).values('user__id').distinct()

    users_repo = [user['user__id'] for user in repo_notifications]
    users_branch = [user['user__id'] for user in branch_notifications]
    users_plan = [user['user__id'] for user in plan_notifications]
    users_planrepository = [user['user__id'] for user in planrepository_notifications]

    users = set()
    if users_repo:
        users.update(users_repo)
    if users_branch:
        users.update(users_branch)
    if users_plan:
        users.update(users_plan)
    if users_planrepository:
        users.update(users_planrepository)

    for user_id in users:
        send_notification_message.delay(build_id, user_id)

    return 'Enqueued send of {} notification messages'.format(len(users))

@django_rq.job('short', timeout=60)
def send_notification_message(build_id, user_id):<commit_msg>use the new field name in task<commit_after>import django_rq
import time
from django import db
from django.conf import settings
from django.core.cache import cache
from django.core.mail import send_mail
from django.template.loader import get_template
from metaci.users.models import User
from metaci.build.models import Build
from metaci.notification.models import RepositoryNotification
from metaci.notification.models import BranchNotification
from metaci.notification.models import PlanNotification
from metaci.notification.models import PlanRepositoryNotification
from metaci.plan.models import PlanRepository


def reset_database_connection():
    db.connection.close()

@django_rq.job('short', timeout=60)
def queue_build_notifications(build_id):
    reset_database_connection()

    build = Build.objects.get(id=build_id)

    status_query = {}

    if build.get_status() in ['queued', 'waiting', 'in_progress']:
        return 'Skipping, build not done yet'
    
    if build.get_status() == 'success':
        status_query['on_success'] = True
    elif build.get_status() == 'fail':
        status_query['on_fail'] = True
    elif build.get_status() == 'error':
        status_query['on_error'] = True
    
    repo_notifications = RepositoryNotification.objects.filter(target = build.repo, **status_query).values('user__id').distinct()
    branch_notifications = BranchNotification.objects.filter(target = build.branch, **status_query).values('user__id').distinct()
    plan_notifications = PlanNotification.objects.filter(target = build.plan, **status_query).values('user__id').distinct()
    planrepository = PlanRepository.objects.filter(plan=build.plan, repo=build.repo)[0]
    planrepository_notifications = PlanRepositoryNotification.objects.filter(target=planrepository, **status_query).values('user__id').distinct()

    users_repo = [user['user__id'] for user in repo_notifications]
    users_branch = [user['user__id'] for user in branch_notifications]
    users_plan = [user['user__id'] for user in plan_notifications]
    users_planrepository = [user['user__id'] for user in planrepository_notifications]

    users = set()
    if users_repo:
        users.update(users_repo)
    if users_branch:
        users.update(users_branch)
    if users_plan:
        users.update(users_plan)
    if users_planrepository:
        users.update(users_planrepository)

    for user_id in users:
        send_notification_message.delay(build_id, user_id)

    return 'Enqueued send of {} notification messages'.format(len(users))

@django_rq.job('short', timeout=60)
def send_notification_message(build_id, user_id):
{'fraction_non_alphanumeric': 0.10120297880465916, 'fraction_numerical': 0.0019094901661256445, 'mean_word_length': 4.986285714285715, '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': '3839148', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1467, 'n_words': 331}