Skip to content

Instantly share code, notes, and snippets.

@DeaconDesperado
Created April 21, 2014 16:34
Show Gist options
  • Save DeaconDesperado/11148066 to your computer and use it in GitHub Desktop.
Save DeaconDesperado/11148066 to your computer and use it in GitHub Desktop.
package com.spotify.wakka
import akka.actor.{Actor, ActorSystem, Props, ActorLogging, ActorRef}
import akka.routing._
import akka.actor.ActorDSL._
import akka.io.IO
import spray.can.Http
import spray.routing._
import spray.httpx.Json4sJacksonSupport
import org.json4s._
import org.json4s.jackson.JsonMethods._
import org.json4s.jackson.Serialization.{read, write}
import spray.util._
import akka.io.Tcp._
import com.spotify.wakka.parseList._
import scala.concurrent.duration._
import org.joda.time.{DateTime => JodaDateTime}
object CacheApp extends App {
import scala.concurrent.ExecutionContext.Implicits.global
implicit val system = ActorSystem("wakka-system")
val cacher:ActorRef = system.actorOf(RoundRobinPool(20).props(Props[CacheActor]))
/* Need to use this thing over and over again for a lot of scheduled calls */
var parsed = parseList.lines.toIndexedSeq map { target =>
cacher ! target
target.justCached
target
}
system.scheduler.scheduleOnce(5 seconds) {
system shutdown
}
}
class CacheActor extends Actor{
def receive = {
case x:CacheTarget => println(x)
}
}
package com.spotify.wakka
import scala.io.Source
import org.joda.time.{DateTime => JodaDateTime}
case class CacheTarget(
date:String,
id:String,
params:String,
lastSaved:JodaDateTime = new JodaDateTime("1970-01-01T00:00:00Z")
){
/* when you cache me, get a new object with a current datetime and all the old fields */
def justCached = this.copy(lastSaved = new JodaDateTime())
}
object parseList {
val source = Source.fromURL(getClass.getResource("/topQueries.tsv"))
val lines = source.getLines.drop(1).map(line => {
val args = line.split("\t")
CacheTarget(args(0), args(1), args(2))
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment