Commit f6eedba8 authored by Administrator's avatar Administrator

[FIX] Processing, async.

parent 08c89e9b
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#app.autodiscover_tasks(lambda: settings.INSTALLED_APPS) #app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
# #
from celery import shared_task from celery import shared_task
from node import models
#@app.task(bind=True) #@app.task(bind=True)
@shared_task @shared_task
...@@ -49,24 +50,26 @@ from parsing.corpustools import add_resource, parse_resources, extract_ngrams, c ...@@ -49,24 +50,26 @@ from parsing.corpustools import add_resource, parse_resources, extract_ngrams, c
@shared_task @shared_task
def apply_workflow(corpus_id): def apply_workflow(corpus_id):
corpus = session.query(Node).filter(Node.id==corpus_id).first() corpus = session.query(Node).filter(Node.id==corpus_id).first()
#
# corpus_django = models.Node.objects.get(id=corpus_id).first()
#
# corpus_django.metadata['Processing'] = 1
# corpus_django.save()
#
# corpus.metadata['Processing'] = 1
# session.add(corpus)
# session.flush()
parse_resources(corpus) parse_resources(corpus)
try:
print("-" *60)
# With Django ORM
corpus_django = models.Node.objects.get(id=corpus_id)
corpus_django.metadata['Processing'] = 0
corpus_django.save()
#TODO With SLA ORM (KO why?)
# corpus.metadata['Processing'] = 0 # corpus.metadata['Processing'] = 0
# session.add(corpus) # session.add(corpus)
## session.flush() # session.flush()
# corpus_django.metadata['Processing'] = 1
# corpus_django.save() except Exception as error:
# print(error)
extract_ngrams(corpus, ['title']) extract_ngrams(corpus, ['title'])
compute_tfidf(corpus) compute_tfidf(corpus)
......
...@@ -2,6 +2,7 @@ from gargantext_web import settings ...@@ -2,6 +2,7 @@ from gargantext_web import settings
from node import models from node import models
__all__ = ['literalquery', 'session', 'cache', 'Session', 'bulk_insert', 'engine', 'get_cursor'] __all__ = ['literalquery', 'session', 'cache', 'Session', 'bulk_insert', 'engine', 'get_cursor']
......
...@@ -7,6 +7,7 @@ from sqlalchemy.orm import aliased ...@@ -7,6 +7,7 @@ from sqlalchemy.orm import aliased
from collections import defaultdict from collections import defaultdict
from datetime import datetime from datetime import datetime
from time import sleep
from threading import Thread from threading import Thread
from node.admin import CustomForm from node.admin import CustomForm
...@@ -51,7 +52,7 @@ def project(request, project_id): ...@@ -51,7 +52,7 @@ def project(request, project_id):
# ... sqlalchemy.func by Resource.type_id is the guilty # ... sqlalchemy.func by Resource.type_id is the guilty
# ISSUE L51 # ISSUE L51
corpus_query = (session corpus_query = (session
.query(Node.id, Node.name, func.count(ChildrenNode.id)) .query(Node.id, Node.name, func.count(ChildrenNode.id), Node.metadata['Processing'])
#.query(Node.id, Node.name, Resource.type_id, func.count(ChildrenNode.id)) #.query(Node.id, Node.name, Resource.type_id, func.count(ChildrenNode.id))
#.join(Node_Resource, Node_Resource.node_id == Node.id) #.join(Node_Resource, Node_Resource.node_id == Node.id)
#.join(Resource, Resource.id == Node_Resource.resource_id) #.join(Resource, Resource.id == Node_Resource.resource_id)
...@@ -66,8 +67,10 @@ def project(request, project_id): ...@@ -66,8 +67,10 @@ def project(request, project_id):
documents_count_by_resourcetype = defaultdict(int) documents_count_by_resourcetype = defaultdict(int)
corpora_count = 0 corpora_count = 0
corpusID_dict = {} corpusID_dict = {}
for corpus_id, corpus_name, document_count in corpus_query:
for corpus_id, corpus_name, document_count, processing in corpus_query:
print(corpus_id, processing)
# Not optimized GOTO ISSUE L51 # Not optimized GOTO ISSUE L51
resource_type_id = (session.query(Resource.type_id) resource_type_id = (session.query(Resource.type_id)
.join(Node_Resource, Node_Resource.resource_id == Resource.id) .join(Node_Resource, Node_Resource.resource_id == Resource.id)
...@@ -82,9 +85,10 @@ def project(request, project_id): ...@@ -82,9 +85,10 @@ def project(request, project_id):
resourcetype = cache.ResourceType[resource_type_id] resourcetype = cache.ResourceType[resource_type_id]
resourcetype_name = resourcetype.name resourcetype_name = resourcetype.name
corpora_by_resourcetype[resourcetype_name].append({ corpora_by_resourcetype[resourcetype_name].append({
'id': corpus_id, 'id' : corpus_id,
'name': corpus_name, 'name' : corpus_name,
'count': document_count, 'count' : document_count,
'processing': processing,
}) })
documents_count_by_resourcetype[resourcetype_name] += document_count documents_count_by_resourcetype[resourcetype_name] += document_count
corpora_count += 1 corpora_count += 1
...@@ -126,6 +130,7 @@ def project(request, project_id): ...@@ -126,6 +130,7 @@ def project(request, project_id):
parent_id = project_id, parent_id = project_id,
type_id = cache.NodeType['Corpus'].id, type_id = cache.NodeType['Corpus'].id,
language_id = language_id, language_id = language_id,
metadata = {'Processing' : 1,}
) )
session.add(corpus) session.add(corpus)
session.commit() session.commit()
...@@ -152,12 +157,15 @@ def project(request, project_id): ...@@ -152,12 +157,15 @@ def project(request, project_id):
print('WORKFLOW ERROR') print('WORKFLOW ERROR')
print(error) print(error)
# redirect to the main project page # redirect to the main project page
# TODO need to wait before response (need corpus update)
sleep(1)
return HttpResponseRedirect('/project/' + str(project_id)) return HttpResponseRedirect('/project/' + str(project_id))
else: else:
print('ERROR: BAD FORM') print('ERROR: BAD FORM')
else: else:
form = CustomForm() form = CustomForm()
# HTML output # HTML output
return render(request, 'project.html', { return render(request, 'project.html', {
'form' : form, 'form' : form,
......
...@@ -83,11 +83,12 @@ ...@@ -83,11 +83,12 @@
<li>{{ key }}</li> <li>{{ key }}</li>
<ul> <ul>
{% for corpus in corpora %} {% for corpus in corpora %}
<li> {% ifnotequal corpus.count 0 %} <li>
<a href="/project/{{project.id}}/corpus/{{corpus.id}}"> {{corpus.name}} </a> , {{ corpus.count }} Documents {% ifequal corpus.processing 1 %}
{% else %}
{{corpus.name}} : <img width="20px" src="{% static "js/libs/img2/loading-bar.gif" %}"></img> Processing, drink a cup of tea, and refresh the page :) {{corpus.name}} : <img width="20px" src="{% static "js/libs/img2/loading-bar.gif" %}"></img> Processing, drink a cup of tea, and refresh the page :)
{% endifnotequal %} {% else %}
<a href="/project/{{project.id}}/corpus/{{corpus.id}}"> {{corpus.name}} </a> , {{ corpus.count }} Documents
{% endifequal %}
<button type="button" class="btn btn-xs btn-default" data-container="body" data-toggle="popover" data-placement="bottom" <button type="button" class="btn btn-xs btn-default" data-container="body" data-toggle="popover" data-placement="bottom"
data-content=' data-content='
<ul> <ul>
......
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