-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathworker.js
29 lines (22 loc) · 863 Bytes
/
worker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'use strict';
var kue = require('kue');
var commenter = require('./lib/commenter');
var config = require('./lib/config');
var redisQueue = kue.createQueue({
redis: config.redisURL
});
var lastCommentTimestamp = 0;
// Process comment jobs
// Pause for commentWait milleseconds between comment submissions
redisQueue.process('comment', function(job, done) {
var now = Date.now();
var waitRemaining = 0;
var nextCommentTimestamp = lastCommentTimestamp + parseInt(config.commentWait);
if (nextCommentTimestamp > now) {
waitRemaining = nextCommentTimestamp - now;
}
setTimeout(function() {
commenter.postPullRequestComment(job.data.commentURL, job.data.comment, job.data.filename, job.data.sha, job.data.line, done);
lastCommentTimestamp = Date.now(); // Use a new, fresh timestamp
}, waitRemaining);
});