Skip to content

Commit

Permalink
yeah, wait for queue
Browse files Browse the repository at this point in the history
ktmud committed Mar 5, 2014
1 parent 7ec801a commit 76c5200
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion tasks/interest/stream.js
Original file line number Diff line number Diff line change
@@ -171,7 +171,8 @@ FetchStream.prototype.fetch = function(start, cb) {
if (code !== 200) {
var err_code = ERRORS[String(code)];
self.user.invalid = err_code || 1;
return self.emit('error', err_code || new Error('douban api responded with ' + code));
err = err || err_code || new Error('douban api responded with ' + code)
return self.emit('error', err);
}
if (err) {
return self.emit('error', err);
2 changes: 1 addition & 1 deletion tools/run.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
export NODE_ENV=${2:-'development'}
export DEBUG='dbj:*'
export DEBUG='dbj:* -*verbose'

if [[ -z $1 ]]; then
echo
10 changes: 9 additions & 1 deletion tools/update.js
Original file line number Diff line number Diff line change
@@ -41,6 +41,13 @@ function updateAll(query) {
process.exit()
}
}
function resume() {
if (tasks.getQueueLength() < 4) {
stream.resume()
} else {
log('[warning] Too many tasks running, wait next..')
}
}
stream.on('data', function(u) {
if (~blacklist.indexOf(u._id)) {
return resume()
@@ -49,13 +56,14 @@ function updateAll(query) {
stream.pause()
counter += 1
u.pull(function() {
stream.resume()
resume()
tasks.interest.collect_book({
user: u,
force: true,
fresh: false
})
u.once('computed', function(e) {
resume()
done(e)
})
})

0 comments on commit 76c5200

Please sign in to comment.