Skip to content

Commit

Permalink
download nltk and language_tool_python on worker ready
Browse files Browse the repository at this point in the history
  • Loading branch information
HadronCollider committed Mar 16, 2024
1 parent 8f3cd06 commit d528cb3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
4 changes: 0 additions & 4 deletions app/nlp/stemming.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import itertools

import nltk
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize, sent_tokenize
from pymorphy2 import MorphAnalyzer

nltk.download('stopwords')
nltk.download('punkt')

MORPH_ANALYZER = MorphAnalyzer()
TASKS = 'задачи:'
Expand Down
28 changes: 19 additions & 9 deletions app/tasks.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import configparser
from configparser import ConfigParser
import os
from os.path import join, exists

from celery import Celery
from celery.signals import worker_ready

import passback_grades
from passback_grades import run_passback
from db import db_methods
from db.db_types import Check
from main.checker import check
from main.parser import parse
from main.check_packs import BASE_PACKS
from root_logger import get_root_logger

config = configparser.ConfigParser()
config = ConfigParser()
config.read('app/config.ini')

TASK_RETRY_COUNTDOWN = 60 # default = 3 * 60
Expand All @@ -33,6 +34,16 @@
celery.conf.timezone = 'Europe/Moscow' # todo: get from env


@worker_ready.connect
def at_start(sender, **k):
from nltk import download
download('stopwords')
download('punkt')

from language_tool_python.download_lt import download_lt
download_lt()


@celery.task(name="create_task", queue='check-solution', bind=True)
def create_task(self, check_info):
check_obj = Check(check_info)
Expand Down Expand Up @@ -67,12 +78,11 @@ def create_task(self, check_info):
self.retry(countdown=TASK_RETRY_COUNTDOWN) # Retry the task, adding it to the back of the queue.


@celery.task(name="passback-task", queue='passback-grade')
def passback_task():
return run_passback()


def remove_files(filepaths):
for filepath in filepaths:
if exists(filepath): os.remove(filepath)


@celery.task(name="passback-task", queue='passback-grade')
def passback_task():
print('Run passback')
return passback_grades.run_passback()

0 comments on commit d528cb3

Please sign in to comment.