run in a main loop

pull/20/head
Johannes J. Schmidt 11 years ago
parent d06cf8383d
commit feff5e3989

@ -23,10 +23,13 @@ Now CouchDB takes care of the couchmagick process.
```ini ```ini
[couchmagick] [couchmagick]
user = mein-user ; optional ; Optional username and password
password = secure ; optional username = mein-user
timeout = 10000 ; in ms. Default is 1000 password = secure
limit = 1000 ; batch size. Default is 100 ; Timeout in ms. Default is 10000
timeout = 1000
; Batch size. Default is 100
limit = 1000
``` ```
Imagemagick Configuration Imagemagick Configuration

@ -19,36 +19,43 @@ var couchmagick = daemon(process.stdin, process.stdout, function() {
var noop = function() {}; var noop = function() {};
couchmagick.get({ couchmagick.get({
// Connection
address: 'httpd.bind_address', address: 'httpd.bind_address',
port: 'httpd.port', port: 'httpd.port',
limit: pkg.name + '.limit',
timeout: pkg.name + '.timeout',
auth: { auth: {
username: pkg.name + '.username', username: pkg.name + '.username',
password: pkg.name + '.password' password: pkg.name + '.password'
} },
// Batching
limit: pkg.name + '.limit',
timeout: pkg.name + '.timeout'
}, function(err, config) { }, function(err, config) {
if (err) { if (err) {
return process.exit(0); return process.exit(0);
} }
var auth = config.auth && config.auth.username && config.auth.password ? // defaults
[config.auth.username, config.auth.password].join(':') : config.timeout = config.timeout || 10000;
null; config.limit = config.limit || 100;
couchmagick.info('using config ' + JSON.stringify(config).replace(/"password":".*?"/, '"password":"***"'));
var couch = url.format({ var couch = url.format({
protocol: 'http', protocol: 'http',
hostname: config.address, hostname: config.address,
port: config.port, port: config.port,
auth: auth auth: config.auth && config.auth.username && config.auth.password ? [ config.auth.username, config.auth.password ].join(':') : null
}); });
var options = { var options = {
limit: config.limit || 100, limit: config.limit,
feed: 'continuous', feed: 'continuous',
timeout: config.timeout || 1000 timeout: config.timeout
}; };
function listen(db, next) { function listen(db, next) {
couchmagick.info('Listening on ' + db); couchmagick.info('Listening on ' + db);
@ -61,20 +68,23 @@ couchmagick.get({
stream.on('end', next); stream.on('end', next);
} }
nano(couch).db.list(function(err, dbs) { // main loop ;)
function run(err) {
if (err) { if (err) {
console.log(err); process.exit(0);
couchmagick.error('Can not get _all_dbs: ' + err.description);
return process.exit(0);
} }
async.eachSeries(dbs, listen, function() { nano(couch).db.list(function(err, dbs) {
couchmagick.info('done.'); if (err) {
process.exit(0); couchmagick.error('Can not get _all_dbs: ' + err.description);
return process.exit(0);
}
async.eachSeries(dbs, listen, run);
}); });
}); }
run();
// TODO: listen to db changes // TODO: listen to db changes
}); });

@ -1,6 +1,6 @@
{ {
"name": "couchmagick", "name": "couchmagick",
"version": "1.1.3", "version": "1.1.4",
"description": "Run ImageMagicks `convert` on CouchDB documents.", "description": "Run ImageMagicks `convert` on CouchDB documents.",
"main": "index.js", "main": "index.js",
"preferGlobal": true, "preferGlobal": true,
@ -30,7 +30,7 @@
"async": "~0.2.9", "async": "~0.2.9",
"event-stream": "~3.0.20", "event-stream": "~3.0.20",
"couchmagick-listen": "~1.0.6", "couchmagick-listen": "~1.0.6",
"couch-daemon": "~1.1.4", "couch-daemon": "~1.2.0",
"nano": "~4.2.1" "nano": "~4.2.1"
}, },
"devDependencies": { "devDependencies": {

Loading…
Cancel
Save