зеркало из https://github.com/microsoft/ghcrawler.git
handle PR comments
This commit is contained in:
Родитель
eb6dd18a7d
Коммит
f2e46dc0b3
|
@ -8,7 +8,7 @@
|
|||
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
|
||||
"stopOnEntry": false,
|
||||
"args": [
|
||||
"test/eventFinderTests.js"
|
||||
"test/*.js"
|
||||
],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"runtimeExecutable": null,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const Q = require('q');
|
||||
const async = require('async');
|
||||
const qlimit = require('qlimit');
|
||||
|
||||
class EventFinder {
|
||||
constructor(requestor, eventStore) {
|
||||
|
@ -18,11 +18,10 @@ class EventFinder {
|
|||
}
|
||||
|
||||
_queueEvents(events, eventSink) {
|
||||
const deferred = Q.defer();
|
||||
const work = (event, cb) => { eventSink.push(event.type, event.url, { payload: event }).then(() => { cb(); }); };
|
||||
const done = this._resolveReject(deferred);
|
||||
async.eachLimit(events, 10, work, done);
|
||||
return deferred.promise;
|
||||
const limit = qlimit(10);
|
||||
return Q.all(events.each(limit(event => {
|
||||
eventSink.push(event.type, event.url, { payload: event });
|
||||
})));
|
||||
}
|
||||
|
||||
getNewEvents(eventSource) {
|
||||
|
@ -31,20 +30,10 @@ class EventFinder {
|
|||
}
|
||||
|
||||
_findNew(events) {
|
||||
const deferred = Q.defer();
|
||||
const work = (event, cb) => { this.eventStore.etag('event', event.url, (err, tag) => { cb(err, !tag); }); };
|
||||
const done = this._resolveReject(deferred);
|
||||
async.filterLimit(events, 10, work, done);
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
_resolveReject(deferred) {
|
||||
return (err, value) => {
|
||||
if (err)
|
||||
deferred.reject(err);
|
||||
else
|
||||
deferred.resolve(value);
|
||||
};
|
||||
const limit = qlimit(10);
|
||||
return Q.all(events.filter(limit(event => {
|
||||
return !this.eventStore.etag('event', event.url, (err, tag));
|
||||
})));
|
||||
}
|
||||
}
|
||||
module.exports = EventFinder;
|
|
@ -1,4 +1,3 @@
|
|||
const async = require('async');
|
||||
|
||||
class WebhookDriver {
|
||||
constructor(trigger, eventFinder, eventSink) {
|
||||
|
@ -15,6 +14,8 @@ class WebhookDriver {
|
|||
}
|
||||
|
||||
_startNext() {
|
||||
// TODO figure out how to handle empty queues so we are not hammering it
|
||||
// Perhaps put a delay in the pop?
|
||||
setTimeout(this.start.bind(this), 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,9 +23,9 @@
|
|||
"url": "https://github.com/microsoft/ghcrawler"
|
||||
},
|
||||
"dependencies": {
|
||||
"async": "^2.1.2",
|
||||
"moment": "2.15.2",
|
||||
"q": "1.4.1"
|
||||
"q": "1.4.1",
|
||||
"qlimit": "^0.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai": "^3.5.0",
|
||||
|
|
Загрузка…
Ссылка в новой задаче