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
[couchmagick]
user = mein-user ; optional
password = secure ; optional
timeout = 10000 ; in ms. Default is 1000
limit = 1000 ; batch size. Default is 100
; Optional username and password
username = mein-user
password = secure
; Timeout in ms. Default is 10000
timeout = 1000
; Batch size. Default is 100
limit = 1000
```
Imagemagick Configuration

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

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

Loading…
Cancel
Save