Skip to content

Commit

Permalink
the new update task
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmud committed Mar 5, 2014
1 parent 8146251 commit 664949e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
10 changes: 4 additions & 6 deletions lib/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,14 @@ if (conf.raven) {
client.on('error', function(e){
_error('sentry is broken: %s', e);
})
}

var URL = require('url');

function express(err, req, res) {
} else {
// just keep silent
message = error = function() {}
}

module.exports = {
client: client,
message: message,
error: error,
express: express,
express: function () {}
};
6 changes: 6 additions & 0 deletions tasks/interest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ collect = User.ensured(function(user, arg) {
require('../compute')[arg.ns]({
user: user,
force: true,
success: function() {
user.emit('computed')
},
error: function(err) {
user.emit('computed', err)
}
})
});

Expand Down
30 changes: 15 additions & 15 deletions tools/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function updateAll(query) {
var now = new Date()
var canExit = true
var blacklist = []
var counter = 0

if (tasks.getQueueLength()) {
log('There are unfinished task. Exit.')
Expand All @@ -31,12 +32,12 @@ function updateAll(query) {
})

User.stream(query, { limit: null }, function(stream) {
function resume() {
if (stream.paused) {
stream.resume()
function done(e) {
if (e) {
log('Sync and compute error: %s', e)
}
if (canExit) {
log('Done, exit.')
log('==== Updated %s users, exit. ======', counter)
process.exit()
}
}
Expand All @@ -46,27 +47,26 @@ function updateAll(query) {
}
canExit = false
stream.pause()
counter += 1
u.pull(function() {
stream.resume()
tasks.interest.collect_book({
user: u,
force: true,
fresh: false,
success: function() {
log('Callback succeed for user %s [%s].', u.uid, u.name)
resume()
},
error: function() {
log('Callback error for user %s [%s].', u.uid, u.name)
resume()
}
fresh: false
})
u.once('computed', function(e) {
done(e)
})
})
log('Queue user %s [%s]', u.uid, u.name)
})
stream.on('close', function() {
log('=== Stream closed. ===')
log('===== Stream closed. %s users in queue. =====', counter)
canExit = true
resume()
if (counter === 0) {
done()
}
})
})
}
Expand Down

0 comments on commit 664949e

Please sign in to comment.