Created
August 3, 2012 13:05
-
-
Save jo/3247561 to your computer and use it in GitHub Desktop.
A CouchDB Worker that fetches a remote JSON and inserts it into a document.
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
/* | |
* CouchDB Worker Fetch JSON | |
* | |
* A CouchDB Worker that fetches a remote JSON and inserts it into a document. | |
* | |
* Author: Johannes J. Schmidt | |
* (c) null2 GmbH, 2012 | |
* MIT Licensed | |
*/ | |
var Worker = require("couchdb-worker"); | |
var request = require("request"); | |
var util = require("util"); | |
new Worker.pool({ | |
name: 'fetch-json', | |
server: process.env.COUCHDB_SERVER || "http://localhost:5984", | |
processor: { | |
check: function(doc) { | |
return doc._id.match(/^\d+$/); | |
}, | |
process: function(doc, done) { | |
request({ | |
url: util.format(this.config.url, doc._id), | |
json: true | |
}, function(error, resp, data) { | |
done(error, data); | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment