Commit c862a29b authored by Administrator's avatar Administrator

[TESTS] celery.

parent baff376c
# -*- coding: utf-8 -*-
import os
import djcelery
from celery import Celery
from django.conf import settings
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'gargantext_web.settings')
app = Celery('gargantext_web')
app.conf.update(
CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend',
)
app.conf.update(
CELERY_RESULT_BACKEND='djcelery.backends.cache:CacheBackend',
)
# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
from celery import shared_task
from parsing.corpustools import add_resource, parse_resources, extract_ngrams, compute_tfidf
@shared_task
def apply_workflow(corpus):
parse_resources(corpus)
extract_ngrams(corpus, ['title'])
compute_tfidf(corpus)
......@@ -17,7 +17,7 @@ PROJECT_PATH = os.path.abspath(PROJECT_PATH)
import djcelery
djcelery.setup_loader()
BROKER_URL = 'amqp://guest:guest@localhost:5672/'
CELERY_IMPORTS=("node.models",)
CELERY_IMPORTS=("node.models","gargantext_web")
# Quick-start development settings - unsuitable for production
......
from celery import shared_task
from parsing.corpustools import add_resource, parse_resources, extract_ngrams, compute_tfidf
@shared_task
def apply_workflow(corpus):
parse_resources(corpus)
extract_ngrams(corpus, ['title'])
compute_tfidf(corpus)
......@@ -18,6 +18,8 @@ import json
from parsing.corpustools import add_resource, parse_resources, extract_ngrams, compute_tfidf
from gargantext_web.celery import apply_workflow
def project(request, project_id):
# SQLAlchemy session
......@@ -142,15 +144,12 @@ def project(request, project_id):
)
# let's start the workflow
try:
def apply_workflow(corpus):
parse_resources(corpus)
extract_ngrams(corpus, ['title'])
compute_tfidf(corpus)
if DEBUG:
apply_workflow(corpus)
else:
thread = Thread(target=apply_workflow, args=(corpus, ), daemon=True)
thread.start()
apply_workflow(corpus)
# if DEBUG:
# apply_workflow(corpus)
# else:
# thread = Thread(target=apply_workflow, args=(corpus, ), daemon=True)
# thread.start()
except Exception as error:
print('WORKFLOW ERROR')
print(error)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment