Created
July 29, 2015 21:45
-
-
Save dhoss/70dbc94b170075e1b7cb to your computer and use it in GitHub Desktop.
how do i make this concurrent?
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
// we want to be asynchronous here because we are doing several API calls | |
def crawlProjectRepos(project: String):Future[List[RepositoryCommitList]] = { | |
Logger.info("crawling " + project + " by API") | |
val repos = reposFor(project) | |
Logger.debug("REPOS " + repos) | |
for (repo <- repos ) { | |
Logger.info("REPO STATUS FOR " + repo + " : " + Await.result(callApi(buildCommitUrl(project, repo)), Duration.Inf)) | |
} | |
val goodRepos = for { | |
(repo, res) <- repos.map { repo => (repo, Await.result(callApi(buildCommitUrl(project, repo)), Duration.Inf)) }; | |
if res.status == 200 | |
} yield (repo, res) | |
Logger.info("SHOULD ONLY CONTAIN 200 STATUS " + goodRepos) | |
val repoCommits = goodRepos.map { gr => //repos.map { repo =>callApi(buildCommitUrl(project, repo)).withFilter(_.status == 200).map { c => | |
Logger.info("RETRIEVING FOR " + gr._1 + ":" +gr._2) | |
scala.concurrent.Future {RepositoryCommitList(gr._1, (gr._2.json \ "values").as[List[JsValue]].map { commit => | |
Commit(0, | |
(commit \ "id").as[String], | |
(commit \ "message").as[String], | |
(commit \ "author" \ "name").as[String], | |
(commit \ "author" \ "emailAddress").as[String], | |
(commit \ "authorTimestamp").as[Option[DateTime]](Reads.optionWithNull(jodaDateReads("yyyy-MM-dd'T'HH:mm:ss'Z"))), | |
None, | |
Option(new DateTime), | |
Option(new DateTime) | |
) | |
}) | |
} | |
//} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment