Skip to content

Commit

Permalink
Mejor logging y manejo de errores en metadatos
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaslavandeira committed Jul 20, 2018
1 parent 1aaeafa commit cef94b3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ def run(self):
data_json = DataJson(node.catalog_url)
IndexMetadataTask.info(self.task,
u'Inicio de la indexación de metadatos de {}'
.format(node.catalog_id))
.format(node.catalog_id))
CatalogMetadataIndexer(data_json, node.catalog_id, self.task, self.doc_type).index()
EnhancedMetaIndexer(node, self.task, self.doc_type).index()
IndexMetadataTask.info(self.task, u'Fin de la indexación de metadatos de {}'
.format(node.catalog_id))
.format(node.catalog_id))

except Exception as e:
IndexMetadataTask.info(self.task,
Expand All @@ -50,7 +50,7 @@ def run(self):
self.elastic.indices.forcemerge(self.index)


@job('indexing', timeout=1000)
@job('indexing', timeout=10000)
def run_metadata_indexer(task):
MetadataIndexer(task).run()
task.refresh_from_db()
Expand Down
24 changes: 16 additions & 8 deletions series_tiempo_ar_api/apps/metadata/queries/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,27 @@ def execute(self):
'count': response.hits.total
}
for hit in response:
start_date = getattr(hit, 'start_date')
if start_date:
start_date = start_date.date()

end_date = getattr(hit, 'end_date')
if end_date:
end_date = end_date.date()

self.response['data'].append({
'field': {
'id': hit['id'],
'description': hit['description'],
'title': hit['title'],
'periodicity': hit['periodicity'],
'start_date': hit['start_date'].date(),
'end_date': hit['end_date'].date(),
'id': getattr(hit, 'id'),
'description': getattr(hit, 'description'),
'title': getattr(hit, 'title'),
'periodicity': getattr(hit, 'periodicity'),
'start_date': start_date,
'end_date': end_date,
},
'dataset': {
'title': hit['dataset_title'],
'title': getattr(hit, 'dataset_title'),
'publisher': {
'name': hit['dataset_publisher_name'],
'name': getattr(hit, 'dataset_publisher_name'),
}
}
})
Expand Down
8 changes: 4 additions & 4 deletions series_tiempo_ar_api/apps/metadata/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from series_tiempo_ar_api.apps.metadata.indexer.metadata_indexer import CatalogMetadataIndexer
from series_tiempo_ar_api.apps.metadata.queries.query import FieldSearchQuery
from series_tiempo_ar_api.apps.metadata.models import IndexMetadataTask
from .utils import get_mock_search, MOCK_DATA
from .utils import get_mock_search, MockData

SAMPLES_DIR = os.path.join(os.path.dirname(__file__), 'samples')
mock.patch.object = mock.patch.object # Hack for pylint inspection
Expand Down Expand Up @@ -86,9 +86,9 @@ def test_enhanced_meta(self):
with mock.patch.object(Search, 'execute', return_value=get_mock_search()):
result = q.execute()

self.assertTrue(result['data'][0]['field']['periodicity'], MOCK_DATA['periodicity'])
self.assertTrue(result['data'][0]['field']['start_date'], MOCK_DATA['start_date'])
self.assertTrue(result['data'][0]['field']['end_date'], MOCK_DATA['end_date'])
self.assertTrue(result['data'][0]['field']['periodicity'], MockData.periodicity)
self.assertTrue(result['data'][0]['field']['start_date'], MockData.start_date)
self.assertTrue(result['data'][0]['field']['end_date'], MockData.end_date)


class CatalogIndexerTests(TestCase):
Expand Down
22 changes: 11 additions & 11 deletions series_tiempo_ar_api/apps/metadata/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
import mock
from datetime import datetime

MOCK_DATA = {
'id': 'algo',
'description': 'description',
'title': 'title',
'dataset_title': 'data_title',
'dataset_publisher_name': 'pub_name',
'periodicity': 'mensual',
'start_date': datetime(2018, 1, 1, 0, 0, 0),
'end_date': datetime(2018, 7, 12, 0, 0, 0),
}

class MockData:
id = 'algo'
description = 'description'
title = 'title'
dataset_title = 'data_title'
dataset_publisher_name = 'pub_name'
periodicity = 'mensual'
start_date = datetime(2018, 1, 1, 0, 0, 0)
end_date = datetime(2018, 7, 12, 0, 0, 0)


def get_mock_search():
mock_search = mock.MagicMock()
mock_search.hits.total = 1
mock_search.__iter__.return_value = [MOCK_DATA]
mock_search.__iter__.return_value = [MockData()]
return mock_search

0 comments on commit cef94b3

Please sign in to comment.