Skip to content

Instantly share code, notes, and snippets.

@ryantanner
ryantanner / application.conf
Created September 12, 2013 22:32
Conspire Akka Configs
akka {
log-config-on-start = on
actor {
provider = "akka.cluster.ClusterActorRefProvider"
}
remote {
log-remote-lifecycle-events = off
netty.tcp {
val some5: Option[Int] = Some(5)
val missingInt: Option[Int] = None
val i: Int = 42 // Good
val i: Int = "Hello" // Compiler error
String st = "Hello" // Compiles
String st = null // Danger! Also compiles!
def findUserById(id: Int): Option[User] = {
@ryantanner
ryantanner / Actors.scala
Last active December 25, 2015 01:09
Akka stuff
class MyCounter extends Actor {
var count = 0
def receive = {
case Add => count + 1
case GetCount = sender tell count
}
}
@ryantanner
ryantanner / Pipeline.scala
Last active December 25, 2015 15:39
Why We Use Actors at Conspire
object UserPipeline {
case class Listen(ref: ActorRef)
case class Start(user: User)
case class Success(user: User)
}
class UserPipeline(
val source: ActorRef // This is an actor that produces a stream of users to be processed
/** Reads queue of new users to index */
class NewUserQueue extends Actor with ActorLogging { ... }
// Define our messages for the NewUserQueue
object NewUserQueue {
case class Listen(ref: ActorRef)
case class StopListen(ref: ActorRef)
case class NewUsers(users: Seq[User])
}
case class User(id: Long, name: String)
class Work { /* ... */ }
class Result { /* --- */ }
case class WorkToBeDone(user: User, work: Work)
case class WorkIsDone(user: User, result: Result)
class Worker extends Actor { /* ... */ }
class BadWorkerCoordinator extends Actor {
akka.actor.deployment {
/analytics/leader {
router = round-robin
nr-of-instances = 100
cluster {
enabled = on
max-nr-of-instances-per-node = 3
allow-local-routees = off
use-role = analytics
}
@ryantanner
ryantanner / AnalyticsLeader.scala
Last active March 19, 2021 18:27
Conspire's implementation of work pulling
class AnalyticsLeader(supervisor: ActorRef) extends Leader[ProcessUser, AnalyticsNode, AnalyticsMessage](supervisor)
#!/usr/bin/env ruby
if `git diff --cached spec` =~ /,\s?(:focus|focus:\s?true|:focus\s?=>\s?true)/
puts "\e[31mPlease focus and remove your :focus tags before committing :)"
exit 1
end
@ryantanner
ryantanner / 20-cloudinit.conf
Last active August 29, 2015 14:07
etcd panic
core@ip-10-0-1-235 ~ $ cat /run/systemd/system/etcd.service.d/20-cloudinit.conf
[Service]
Environment="ETCD_ADDR=10.0.1.235:4001"
Environment="ETCD_CLUSTER_ACTIVE_SIZE=3"
Environment="ETCD_DISCOVERY=http://10.0.0.66:4001/v2/keys/_etcd/registry/cluster-dev-f9ekeksid832ik4k"
Environment="ETCD_NAME=10-0-1-235"
Environment="ETCD_PEER_ADDR=10.0.1.235:7001"
Environment="ETCD_TRACE=*"
Environment="ETCD_VERY_VERY_VERBOSE=true"