Skip to content

Instantly share code, notes, and snippets.

@xkrsz
Created March 31, 2016 18:21
Show Gist options
  • Save xkrsz/77c7156b352476a347e54debed9d50f0 to your computer and use it in GitHub Desktop.
Save xkrsz/77c7156b352476a347e54debed9d50f0 to your computer and use it in GitHub Desktop.
hell
module.exports = function(agenda, log, reqs, moment) {
agenda.define('update rescue time', function(job, done) {
UserElements.find({rescue_time: {$ne: null}}, function(e, users) {
if(e) log.error(e);
if(users.length > 0) {
users.forEach(function(user) {
reqs.rescueTime(user.rescue_time, function(e, r, b) {
if(b) {
b[0].date = moment(b[0].date);
var date = b[0].date,
now = moment();
if(date.year() == now.year() &&
date.dayOfYear() == now.dayOfYear() - 1) {
var rescueTime = new RescueTime(b[0]);
rescueTime.owner = user.username;
rescueTime.created_at = now;
rescueTime.save(function(e, rescueTime) {
if(e) log.error(e);
if(rescueTime) {
log.info({username: user.username, date: moment(date, 'YYYY-MM-DD')},
"Rescue Time data saved.");
}
});
}
}
});
});
}
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment