Skip to content

Commit

Permalink
Merge pull request #36 from Notastica/fix-has-more-than-1-persistence…
Browse files Browse the repository at this point in the history
…-module

Fix has more than 1 persistence module
  • Loading branch information
Panthro committed Aug 28, 2016
2 parents fc2544a + 2498712 commit 7cdf906
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data-feed-orchestrator",
"version": "0.2.0",
"version": "0.2.1",
"description": "A data feed orchestrator",
"main": "lib/index.js",
"files": [
Expand Down Expand Up @@ -39,7 +39,8 @@
"url": "https://notastica.org"
},
"pre-commit": [
"validate"
"lint",
"audit"
],
"dependencies": {
"@google/maps": "^0.1.0",
Expand Down
8 changes: 8 additions & 0 deletions src/modules/geocoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const geocoding = (options) => {

sort[options.sortEsQueryField] = { order: options.sortEsQueryOrder };
query.body.sort.push(sort);
logger.debug(`Built query ${query}`);

return query;

Expand All @@ -120,12 +121,15 @@ const geocoding = (options) => {
const populateFromElasticsearch = function (esClient, message) {
// Query elasticsearch and return an object if found
return new Promise((resolve) => {
logger.debug('Trying to populate from elasticsearch');
esClient.search(buildEsQuery(message))
.then((resp) => {
const hits = resp.hits.hits;

logger.debug(`Elasticearch returned ${hits.length} hits`);
if (hits && hits.length > 0) {
// populate the destination field in the message
logger.debug('Updating message with data from elasticsearch');
message[options.destinationField] = hits[0]._source[options.destinationField];
}
// delivery the message, populated or not
Expand Down Expand Up @@ -154,7 +158,11 @@ const geocoding = (options) => {
return populateFromElasticsearch(esClient, message);
}
return message;
}).catch((err) => {
logger.info('There was an error querying elasticsearch', err);
return message;
}).then((updatedMessage) => {
updatedMessage = updatedMessage || message; // in case for some reason we don't get an updated version
if (updatedMessage[options.destinationField]) {
logger.info('Already populated in elasticsearch, using latest value');
return updatedMessage;
Expand Down
2 changes: 1 addition & 1 deletion src/orchestrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class Orchestrator {
* @private
*/
_hasPersistenceModule() {
return this.modulesCollection.find({ type: 'persistence' }).length === 0;
return this.modulesCollection.find({ type: 'persistence' }).length > 0;
}

/**
Expand Down

0 comments on commit 7cdf906

Please sign in to comment.