Instantly share code, notes, and snippets.

What would you like to do?
import scala.language.postfixOps
import scala.concurrent._
import scala.concurrent.duration._
import akka.pattern.pipe
import akka.cluster.routing._
* Concept and some code lifted from
*, thanks Josh!
object StatApp extends App {
val system = ActorSystem("StatsApp")
import system.dispatcher
val publisher = system.actorOf(Props(new Publisher()))
/* Explicitly uses the default metrics selector */
val statistics = system.actorOf(Props(new Statistics(publisher))
totalInstances = 50, routeesPath = "/user/statsWorker",
allowLocalRoutees = true))), name = "statsRouter")
/* stubbed out: imagine this dynamically gets github projects */
val projects: Set[Project] = Set.empty
system.scheduler.schedule(Duration.Zero, 60 seconds) {
println("Sending project")
projects foreach (statistics ! _)
class Statistics(publisher: ActorRef) extends Actor {
import context.dispatcher
val api = new Api()
def receive = { case p: Project statistics(p) }
def statistics(project: Project): Unit = {
val pullRequests = api pullrequests project
val collaborators = api collaborators project
pullRequests zip collaborators map {
case (prs, cs) ProjectStatistics(project, cs, prs)
} pipeTo publisher
/* Stubbed out for brevity */
class Publisher extends Actor {
def receive = {
case event: ProjectStatistics
// converts and pushes to Restful consumers
/* Stubbed out for brevity */
class Api {
implicit val ctx =
def pullrequests(proj: Project): Future[Set[PullRequest]] =
def collaborators(proj: Project): Future[Set[Collaborator]] =
case class Project(owner: String, name: String)
case class Collaborator(name: String)
case class PullRequest(project: Project, id: String,
contributor: String)
case class ProjectStatistics(project: Project,
collaborators: Set[Collaborator],
pullreqs: Set[PullRequest])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment