Skip to content

Commit

Permalink
Merge pull request #244 from pelias/remove-legacy-usage-of-temp
Browse files Browse the repository at this point in the history
fix(worker): Remove legacy usage of `temp` module
  • Loading branch information
orangejulius authored Nov 9, 2018
2 parents 0be636f + b3d962d commit 6de6da5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"request": "^2.83.0",
"simplify-js": "^1.2.1",
"stable": "^0.1.8",
"temp": "^0.8.3",
"through2": "^3.0.0",
"through2-filter": "^3.0.0",
"through2-map": "^3.0.0",
Expand All @@ -54,7 +53,8 @@
"precommit-hook": "^3.0.0",
"proxyquire": "^2.0.0",
"tap-dot": "^2.0.0",
"tape": "^4.2.2"
"tape": "^4.2.2",
"temp": "^0.8.3"
},
"pre-commit": [
"lint",
Expand Down
47 changes: 22 additions & 25 deletions src/pip/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const PolygonLookup = require('polygon-lookup');
const readStream = require('./readStream');
const fs = require('fs');
const path = require('path');
const temp = require('temp').track();

const layer = process.title = process.argv[2];
const datapath = process.argv[3];
Expand All @@ -33,33 +32,31 @@ process.on('SIGTERM', () => {
});

readStream(datapath, layer, localizedAdminNames, (features) => {
temp.mkdir('wof_cache', (err, temp_dir) => {
// find all the properties of all features and write them to a file
// at the same time, limit the feature.properties to just Id since it's all that's needed in the worker
const data = features.reduce((acc, feature) => {
acc[feature.properties.Id] = feature.properties;
feature.properties = {
Hierarchy: feature.properties.Hierarchy
};
return acc;
}, {});
// find all the properties of all features and write them to a file
// at the same time, limit the feature.properties to just Id since it's all that's needed in the worker
const data = features.reduce((acc, feature) => {
acc[feature.properties.Id] = feature.properties;
feature.properties = {
Hierarchy: feature.properties.Hierarchy
};
return acc;
}, {});

adminLookup = new PolygonLookup( { features: features } );
adminLookup = new PolygonLookup( { features: features } );

process.on('message', msg => {
switch (msg.type) {
case 'search' : return handleSearch(msg);
default : logger.error('Unknown message:', msg);
}
});
process.on('message', msg => {
switch (msg.type) {
case 'search' : return handleSearch(msg);
default : logger.error('Unknown message:', msg);
}
});

// alert the master thread that this worker has been loaded and is ready for requests
process.send( {
type: 'loaded',
layer: layer,
data: data,
seconds: ((Date.now() - startTime)/1000)
});
// alert the master thread that this worker has been loaded and is ready for requests
process.send( {
type: 'loaded',
layer: layer,
data: data,
seconds: ((Date.now() - startTime)/1000)
});
});

Expand Down

0 comments on commit 6de6da5

Please sign in to comment.