def getBuildInfo()

in app/controllers/ProjectsController.scala [110:143]


  def getBuildInfo(projectId:String, branchName:String, jobName:String) = IsAdminAsync { uid=> req=>
    val cacheKey = s"$projectId-$branchName-$jobName"
    scalacache.get(cacheKey).flatMap({
      case Some(buildInfo)=>
        logger.debug(s"Serving result for project id $projectId, branch $branchName, job $jobName from cache...")
        Future(Some(Right(buildInfo)))  //we got a hit from the cache, don't bother going to the external service
      case None=> //nothing from the cache, look it up from the external service
        logger.debug(s"Serving result for project id $projectId, branch $branchName, job $jobName from origin...")
        findNewBuildInfo(projectId, branchName, jobName).flatMap({
          case result @ Some(Right(buildInfo))=>
            scalacache.put(cacheKey)(buildInfo, maybeCacheTTL).map(_=>result)
          case result @ _=>
            Future(result)
        })
    }).map({
        case Some(Right(buildInfo))=>
          Ok(buildInfo.asJson)
        case Some(Left(parseErr))=>
          InternalServerError(GenericErrorResponse("invalid_data", s"extracted information failed to parse: $parseErr").asJson)
        case None=>
          NotFound(GenericErrorResponse("not_found", "no build info can be found for that job of that branch of that project. Consult the logs for more details").asJson)
      }).recover({
      case httpErr:HttpError=>
        if(httpErr.getStatusCode==StatusCodes.NotFound) {
          NotFound(GenericErrorResponse("not_found", "build info is not available from this build").asJson)
        } else {
          logger.error(s"Could not extract build info: ${httpErr.getMessage}")
          InternalServerError(GenericErrorResponse("error", httpErr.getMessage).asJson)
        }
      case err:Throwable=>
        logger.error(s"Could not extract build info: ${err.getMessage}", err)
        InternalServerError(GenericErrorResponse("error", err.getMessage).asJson)
    })
  }