Skip to content

Commit

Permalink
Skip indexed repositories, better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
anvaka committed Jan 16, 2016
1 parent e113ebf commit a58a858
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
20 changes: 19 additions & 1 deletion indexRepoInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ getUnindexedRepositories()
.then(crawlNextChunk);

function crawlNextChunk(projects) {
console.log((new Date().toString()) + ' remaining to index: ' + projects.length);
if (projects.length === 0) {
console.log('All done. No more projects to index.');
client.unref();
return;
}

processNext(projects, 10);
processNext(projects, 5);
}

function processNext(array, count) {
Expand Down Expand Up @@ -52,14 +53,31 @@ function saveRepositories(repositories) {
}

function getUnindexedRepositories() {
var totalIndexed = 0;
return client.keysAsync('repo:*').then(function(keys) {
return keys.map(toName);
})
.map(toNameIfNotExist, {concurrency: 3})
.filter(function(x) {
if (!x) totalIndexed += 1;
return x;
})
.then(function(repositories) {
console.log('Total indexed: ' + totalIndexed);
return repositories;
});

function toName(repo) {
// remove 'repo:' prefix from the key:
return repo.substr(5);
}

function toNameIfNotExist(repo) {
return client.existsAsync('rinfo:' + repo)
.then(function(exists) {
return exists ? '' : repo;
});
}
}

function printError(repo) {
Expand Down
8 changes: 4 additions & 4 deletions lib/githubClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function githubClient(token) {

function getRepositoriesInfo(repositories) {
return Promise.map(repositories, toRequest, {
concurrency: 3
concurrency: 2
});
function toRequest(repoName) {
var detailsRequest = createRequestArgs(REPO_DETAILS + repoName + '?' + tokenPart);
Expand All @@ -38,9 +38,9 @@ function githubClient(token) {
return githubRequest(detailsRequest).then(extractRepoInfo).catch(handleError);

function handleError(err) {
if (err && err.statusCode === 404) {
console.log('repository not found: ' + repoName);
return { name: repoName, error: 404 };
if (err) {
console.log('!!Failed to fetch ' + repoName + ': ' + err);
return { name: repoName, error: err.statusCode };
}
throw err;
}
Expand Down
6 changes: 6 additions & 0 deletions lib/githubRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ function githubRequest(options, followNext) {
if (reason.statusCode === 403) {
failedCount = 0;
var headers = reason.response.headers;
var body = JSON.parse(reason.response.body);
if (body.block) {
// This means the repository is blocked.
throw reason;
}
// Otherwise, we just ran out of rate limit
return getRateLimitPromiseFromHeaders(headers);
} else if (reason.statusCode == 404) {
failedCount = 0;
Expand Down

0 comments on commit a58a858

Please sign in to comment.