#coding: utf-8 import logging import json from django.db import close_connection from celery.result import AsyncResult from journalmanager import tasks from thrift import spec from scielomanager import connectors LOGGER = logging.getLogger(__name__) ARTICLE_ES_CLIENT = connectors.ArticleElasticsearch() ERRNO_NS = { 'IntegrityError': 1, 'ValueError': 2, } def resource_cleanup(tocall): """ O Celery vaza recursos de conexão com o BD quando utiliza o ORM como backend de tarefas. Além disso, o próprio ORM do Django utiliza o signal `request_finished` para disparar a rotina `django.db.close_connection`, e como a interface RPC é dissociada dos ciclos convencionais de request/response, devemos executar essa limpeza manualmente. """ def wrapper(*args, **kwargs): try: return tocall(*args, **kwargs) finally:
def _create_index(): client = connectors.ArticleElasticsearch() client.create_index()
def _delete_index(): client = connectors.ArticleElasticsearch() client.delete_index()
from PIL import Image from scielomanager.celery import app from scielomanager import connectors from . import models logger = get_task_logger(__name__) BASIC_ARTICLE_META_PATH = os.path.join( os.path.dirname(os.path.abspath(__file__)), 'basic_article_meta.sch') # instâncias de isoschematron.Schematron não são thread-safe ARTICLE_META_SCHEMATRON = isoschematron.Schematron( file=BASIC_ARTICLE_META_PATH) elasticsearch_client = connectors.ArticleElasticsearch() def _gen_es_struct_from_article(article): """Retorna `article` em estrutura de dados esperada pelo Elasticsearch. """ paths = article.XPaths values_to_struct_mapping = [ ['abbrev_journal_title', paths.ABBREV_JOURNAL_TITLE], ['epub', paths.ISSN_EPUB], ['ppub', paths.ISSN_PPUB], ['volume', paths.VOLUME], ['issue', paths.ISSUE], ['year', paths.YEAR], ['doi', paths.DOI],