hoodie-plugins-manager
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -61,3 +61,3 @@ /** | ||
// idle pool to check we haven't missed anything | ||
setInterval(function () { | ||
var interval = setInterval(function () { | ||
exports.refreshOldest(updated, idle); | ||
@@ -68,3 +68,2 @@ }, 5000); | ||
db_updates.listen(couch_url, function (err, data) { | ||
console.log(['got db_updates event', data]); | ||
if (err) { | ||
@@ -112,5 +111,16 @@ console.log('[changes_pool] Error: ' + err); | ||
}; | ||
f.isSubscribed = function (db_name) { | ||
return !!(_.detect(idle.concat(updated.tasks), function (x) { | ||
return x.db === db_name; | ||
})); | ||
}; | ||
f.remove = function (db_name) { | ||
exports.removeDB(updated, idle, db_name); | ||
}; | ||
f.stop = function (callback) { | ||
updated.tasks = []; | ||
idle = []; | ||
clearInterval(interval); | ||
callback(); | ||
}; | ||
return f; | ||
@@ -129,3 +139,2 @@ }; | ||
var queue = async.queue(function (task, callback) { | ||
console.log("calling all_docs"); | ||
var db_url = url.resolve(couch_url, encodeURIComponent(task.name)); | ||
@@ -150,3 +159,2 @@ var q = { | ||
feed.on('change', function (change) { | ||
console.log(['change event', change]); | ||
if (change.doc) { | ||
@@ -157,8 +165,14 @@ callback(null, change); | ||
feed.on('error', callback); | ||
feeds[db] = feed; | ||
feeds[db] = {feed: feed, db: db, query: query}; | ||
queue.push({name: db, handler: callback}); | ||
}; | ||
f.remove = function (db_name) { | ||
var feed = feeds[name]; | ||
f.isSubscribed = function (db_name) { | ||
return !!(_.detect(_.values(feeds), function (x) { | ||
return x.db === db_name; | ||
})); | ||
}; | ||
f.remove = function (db_name, /*optional*/callback) { | ||
var feed = feeds[db_name].feed; | ||
if (feed) { | ||
@@ -173,3 +187,6 @@ feed.once('error', function (err) { | ||
feed.once('stop', function () { | ||
delete feeds[name]; | ||
delete feeds[db_name]; | ||
if (callback) { | ||
callback(); | ||
} | ||
}); | ||
@@ -180,2 +197,7 @@ feed.stop(); | ||
f.stop = function (callback) { | ||
var names = Object.keys(feeds); | ||
async.map(names, f.remove, callback); | ||
}; | ||
return f; | ||
@@ -191,3 +213,2 @@ }; | ||
exports.doRequests = function (db, callback) { | ||
//console.log(['doRequests', db.db]); | ||
// make each request in series and return the updated request objects | ||
@@ -212,3 +233,2 @@ async.mapSeries(db.requests, exports.requestChanges, function (err, reqs) { | ||
exports.requestChanges = function (req, callback) { | ||
//console.log(['pool requestChanges', req.db, req.query]); | ||
// don't do continuous or longpoll feeds | ||
@@ -215,0 +235,0 @@ req.query.feed = 'normal'; |
@@ -39,2 +39,6 @@ var databases_api = require('hoodie-plugins-api/lib/databases'), | ||
}; | ||
if (pool.isSubscribed(name)) { | ||
// already subscribed | ||
return callback(); | ||
} | ||
function docChangeEvent(doc) { | ||
@@ -56,2 +60,5 @@ doc = databases_api.parseDoc(doc); | ||
}); | ||
if (callback) { | ||
return callback(); | ||
} | ||
}; | ||
@@ -61,4 +68,2 @@ | ||
pool.remove(name); | ||
// TODO: remove this from API docs and eliminate callback argument | ||
if (callback) { | ||
@@ -70,4 +75,3 @@ return callback(); | ||
tm.stop = function (callback) { | ||
var names = Object.keys(feeds); | ||
async.map(names, tm.removeSource, callback); | ||
pool.stop(callback); | ||
}; | ||
@@ -74,0 +78,0 @@ |
{ | ||
"name": "hoodie-plugins-manager", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Run and dispatch events to Hoodie plugin server extensions", | ||
@@ -14,7 +14,7 @@ "dependencies": { | ||
"devDependencies": { | ||
"multicouch": "latest", | ||
"multicouch": "0.8.1", | ||
"request": "2.22.0", | ||
"mkdirp": "0.3.5", | ||
"rimraf": "2.2.1", | ||
"nodeunit": "latest" | ||
"nodeunit": "0.8.1" | ||
}, | ||
@@ -21,0 +21,0 @@ "main": "lib/index.js", |
@@ -63,4 +63,2 @@ var MultiCouch = require('multicouch'), | ||
prefix: opts.data_dir, | ||
couchdb_path: '/usr/bin/couchdb', | ||
default_sys_ini: '/etc/couchdb/default.ini', | ||
respawn: false // otherwise causes problems shutting down | ||
@@ -67,0 +65,0 @@ }; |
@@ -569,3 +569,3 @@ var plugins_manager = require('../lib/index'), | ||
test.same(changed_tasks.sort(), [ | ||
'bar', 'baz', 'foo', 'quux' | ||
'bar', 'baz', 'foo', 'quux', 'qux' | ||
]); | ||
@@ -572,0 +572,0 @@ manager.stop(test.done); |
97925
14
1380