Created
March 31, 2016 18:21
-
-
Save xkrsz/77c7156b352476a347e54debed9d50f0 to your computer and use it in GitHub Desktop.
hell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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