Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Commit

Permalink
iss #22: fetcher stat in /status
Browse files Browse the repository at this point in the history
  • Loading branch information
maizy committed Aug 7, 2014
1 parent b384ced commit 374aab9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
12 changes: 11 additions & 1 deletion app/controllers/Status.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,23 @@ import play.api.mvc.{Action, Controller}
import play.core.PlayVersion
import hedgehog.controllers.WithViewContext
import hedgehog.Config.playAppInstance
import hedgehog.clients.github.RepositoriesFetcher

/**
* Copyright (c) Nikita Kovaliov, maizy.ru, 2013-2014
* See LICENSE.txt for details.
*/
object Status extends Controller with WithViewContext {
def index = Action { implicit request =>
Ok(views.html.status(playAppInstance, PlayVersion.current, PlayVersion.scalaVersion))
val fetcherStat = Map(
"hits" -> RepositoriesFetcher.playAppInstance.hits,
"misses" -> RepositoriesFetcher.playAppInstance.misses
)
Ok(views.html.status(
playAppInstance,
PlayVersion.current,
PlayVersion.scalaVersion,
fetcherStat
))
}
}
10 changes: 9 additions & 1 deletion app/hedgehog/clients/github/RepositoriesFetcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@ class RepositoriesFetcher(client: Client) {
val repositories: mutable.Map[String, Option[Seq[Repo]]] = mutable.Map.empty
val lastFetched: mutable.Map[String, Option[DateTime]] = mutable.Map.empty

private var hits_ = 0
private var misses_ = 0

implicit val context = client.context

def getRepos(accountsSettings: Seq[AccountSettings]): Future[Seq[Repo]] = {
hits_ += 1
//TODO: cache
fetch(accountsSettings)
}

private def fetch(accountsSettings: Seq[AccountSettings]): Future[Seq[Repo]] = {
val requests = Future.sequence{
misses_ += 1
val requests = Future.sequence {
accountsSettings.map(client.getRepos)
}
val future = requests map {
Expand All @@ -37,6 +42,9 @@ class RepositoriesFetcher(client: Client) {
List()
}
}

def hits = hits_
def misses = misses_
}


Expand Down
15 changes: 14 additions & 1 deletion app/views/status.scala.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@(config: hedgehog.Config, playVersion: String, scalaVersion: String)(implicit c: hedgehog.views.ViewContext)
@(config: hedgehog.Config, playVersion: String, scalaVersion: String, fetcherStats: Map[String, Int])(implicit c: hedgehog.views.ViewContext)

@templates.main(nav = "status") {
<h1>@c.Messages("Status")</h1>
Expand Down Expand Up @@ -45,4 +45,17 @@ <h3>@c.Messages("Versions")</h3>
</tr>
</tbody>
</table>

<h3>@c.Messages("Fetcher_stats")</h3>

<table class="table">
<tbody>
@for((param, value) <- fetcherStats) {
<tr>
<td>@param</td>
<td>@value</td>
</tr>
}
</tbody>
</table>
}
1 change: 1 addition & 0 deletions conf/messages
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ Go_search_button = Go!

Versions=Versions
Some_configs=Some configs
Fetcher_stats = Fetcher stat

0 comments on commit 374aab9

Please sign in to comment.