Skip to content

Instantly share code, notes, and snippets.

@hampelm
Created January 16, 2018 00:26
Show Gist options
  • Save hampelm/76dea1c4fd7513129729ed1d18fdc2b5 to your computer and use it in GitHub Desktop.
Save hampelm/76dea1c4fd7513129729ed1d18fdc2b5 to your computer and use it in GitHub Desktop.
var pg = require('pg');
var QueryStream = require('pg-query-stream');
var JSONStream = require('JSONStream');
queue = require('kue').createQueue();
pg.connect(function(err, client, done) {
if (err) throw err;
var query = new QueryStream(
'select address from voter_addr where status is null;',
);
var stream = client.query(query);
stream.on('end', done);
var batch = [];
stream.pipe(row => {
batch.push(row.rows[0].address);
if (set.length === 1000) {
queue
.create('batch', {
batch,
})
.save();
batch = [];
}
});
});
queue.process('batch', function(job, done) {
geocode(batch, done);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment