Created
July 24, 2015 17:07
-
-
Save myndzi/d6841a0ca9afbd035c00 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var request = Promise.promisifyAll(require('request')); | |
function getIssues() { | |
return request(options) | |
.spread(r, body) { | |
if (r.statusCode !== 200) { | |
console.log("unsuccessful status code!"); | |
console.log(body); | |
return; | |
} | |
issues = issues.concat(body["issues"]); | |
maxResults = body["total"]; | |
options.body.startAt += numToRequest; | |
if (issues.length < maxResults) { | |
return Promise.delay(timeToWaitAfterRequest).then(getIssues); | |
} | |
console.log("finished getting data, sorting it now"); | |
listifyIssues(); // is this sync or async? assuming sync | |
return putIssuesInDatabase(); | |
}) | |
.catch(function (e) { | |
// the caller of getIssues should probably be catching and logging, not this function | |
console.log("Error!"); | |
console.log(e); | |
// rethrow ? | |
}) | |
} | |
getIssues().then(function (result) { | |
// result is the return from knex | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment