-
-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Use Libpostal service #146
Open
orangejulius
wants to merge
5
commits into
master
Choose a base branch
from
libpostal-service
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
123a119
Require pelias-microservice-wrapper
orangejulius 6e786db
feat(libpostal): Use libpostal service
orangejulius 1639d65
Use standard baseimage
orangejulius 9274136
Remove node-postal dependency
orangejulius 72ae93f
Force-loading libpostal is no longer needed
orangejulius File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# base image | ||
FROM pelias/libpostal_baseimage | ||
FROM pelias/baseimage | ||
|
||
# dependencies | ||
RUN apt-get update && \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const mock_libpostal = require('../test/lib/mock_libpostal'); | ||
|
||
// This module is a wrapper around the actual libpostal service library | ||
// and the mock libpostal library | ||
// it allows an environment variable to switch which library is used in application code | ||
|
||
let libpostal_module; | ||
function get_libpostal() { | ||
// return the mock library if MOCK_LIBPOSTAL env var is set | ||
if (process.env.MOCK_LIBPOSTAL) { | ||
return mock_libpostal; | ||
// otherwise return the actual service | ||
} else { | ||
// lazy load the libpostal module so that tests can skip configuring the service | ||
if (!libpostal_module) { | ||
libpostal_module = require( '../libpostal/service' ); | ||
} | ||
return libpostal_module; | ||
} | ||
} | ||
|
||
module.exports = get_libpostal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const microservice_wrapper = require('pelias-microservice-wrapper'); | ||
const pelias_config = require('pelias-config').generate(); | ||
|
||
const LibpostalServiceConfig = class extends microservice_wrapper.ServiceConfiguration { | ||
constructor(configBlob) { | ||
super('libpostal', configBlob); | ||
} | ||
getUrl(params) { | ||
return this.baseUrl + params.endpoint; | ||
} | ||
getParameters(params) { | ||
return { | ||
address: params.address | ||
}; | ||
} | ||
}; | ||
|
||
// use the 'services.libpostal' config entry if available, otherwise fall back to 'api.services.libpostal' | ||
const config_entry = pelias_config.get('services.libpostal') || pelias_config.get('api.services.libpostal'); | ||
|
||
if (!config_entry) { | ||
throw new Error('Libpostal configuration not found in `services.libpostal` or `api.services.libpostal`'); | ||
} | ||
|
||
// create an instance of the libpostal service | ||
const libpostal_service = microservice_wrapper.service( | ||
new LibpostalServiceConfig(config_entry) | ||
); | ||
|
||
// create an object that looks like the interface to `node-postal` but uses a remote service | ||
module.exports = { | ||
expand: { | ||
expand_address: function(param, callback) { | ||
const params = { | ||
endpoint: 'expand', | ||
address: param | ||
}; | ||
|
||
// the libpostal service will not handle an empty parameter | ||
// so return empty array immediately | ||
if (!param) { | ||
return callback(null, []); | ||
} | ||
libpostal_service(params, callback); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the idea behind this syntax? It seems... verbose
wouldn't that be simpler as:
I see that
streetAnalyzeCallback
isn't referenced anywhere else in the file so I'm guessing it's for stack traces?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see in another file below that you're using the syntax:
I think that syntax is much cleaner, and it allows you to leave most of the code untouched and avoids the closure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was simply because I was hoping to avoid having to use
async/await
syntax at all in this PR. Despite the verboseness I'm honestly not a fan of additional language complexity. Functions are well understood by everyone :)However, because later on we are depending on many calls to libpostal returning before proceeding, using
Promisify.all
is basically the only way to get the behavior we want.Since we're already going to be using the new syntax, I'll update this code to use it as well.