Skip to content

Instantly share code, notes, and snippets.

View jchapuis's full-sized avatar
🤓

Jonas Chapuis jchapuis

🤓
View GitHub Profile
@jchapuis
jchapuis / Markdium-Scala.scala
Created May 10, 2020 19:38
Markdium-Orchestrating startup and shutdown in Scala
def stopService(service: Service): Task[Either[ServiceStopError, Service]] =
Task.deferFuture {
service.triggerStop()
service.stopped.map(_.map(_ => service))
}.timeout(duration).onErrorRecover {
case _: TimeoutException => ServiceStopTimeoutError(service, duration).asLeft
}
@jchapuis
jchapuis / Markdium-Scala.scala
Created May 10, 2020 19:38
Markdium-Orchestrating startup and shutdown in Scala
"notify stopped with error in case of service stop timeout" in {
implicit val scheduler = TestScheduler()
val serviceA = Service.withName("A").withStopper(() => Future.never).build
val serviceB = Service.withName("B").withStopper(() => Future.successful(())).build
Given("a started composite with finite stopped timeout")
implicit val stoppedTimeout = FiniteStoppedTimeout(30 seconds)
val composite = new CompositeService(serviceA, serviceB)
composite.start()
scheduler.tick(1 second)
@jchapuis
jchapuis / Markdium-Scala.scala
Created May 10, 2020 19:38
Markdium-Orchestrating startup and shutdown in Scala
object CoordinatedShutdownHttpHelpers {
implicit class FluentHttpCoordinatedShutdown(coordinatedShutdown: CoordinatedShutdown)(
implicit val system: ActorSystem
) {
private implicit val executionContext: ExecutionContext = system.dispatcher
def addHttpBinding(
binding: Http.ServerBinding,
pendingRequestsHardDeadline: FiniteDuration,
unbindingDelay: FiniteDuration
@jchapuis
jchapuis / Markdium-Scala.scala
Created May 10, 2020 19:38
Markdium-Orchestrating startup and shutdown in Scala
trait Service extends Stoppable[Either[E, Unit]] {
def start(): Future[E, Unit]
def name: String
}
@jchapuis
jchapuis / Markdium-Scala.scala
Created May 10, 2020 19:38
Markdium-Orchestrating startup and shutdown in Scala
Service
.withName("in-memory-cache")
.withFallibleStarter{ () => cache.loadAsync() : Future[Either[StartError, Unit]] }
.build
@jchapuis
jchapuis / Markdium-Scala.scala
Created May 10, 2020 19:38
Markdium-Orchestrating startup and shutdown in Scala
val akkaApplicationService: Service = builder
.startSystemDependent(SomeEtcdService())
.thenStartHttp(
HttpServiceDefinition(
new AkkaControllers().routes,
serverConfig.host,
serverConfig.port,
serverConfig.hardDeadline,
serverConfig.unbindingDelay
)
@jchapuis
jchapuis / Markdium-Scala.scala
Created May 10, 2020 19:38
Markdium-Orchestrating startup and shutdown in Scala
Service
.withName("topic-dependent")
.withFallibleStarter( () =>
(for {
_ <- EitherT(KafkaAdmin().ensureTopicCreated("foobar-topic"))
_ <- EitherT.right[KafkaAdmin.TopicCreationFailed](consumer("foobar-topic"))
} yield ()).value
)
.build
@jchapuis
jchapuis / iterm2-solarized.md
Created May 4, 2020 18:03 — forked from kevin-smets/iterm2-solarized.md
iTerm2 + Oh My Zsh + Solarized color scheme + Source Code Pro Powerline + Font Awesome + [Powerlevel10k] - (macOS)

Default

Default

Powerlevel10k

Powerlevel10k

implicit def commandProcessor(
implicit timestampProvider: TimestampProvider
): CommandProcessor[Ride, RideCommand, RideEvent] = (_, command) => command match {
...
case StartRide(rideID) => List(RideStarted(rideID, timestampProvider.timestamp))
case CompleteRide(rideID) => List(RideCompleted(rideID, timestampProvider.timestamp))
}
implicit val eventApplier: EventApplier[Ride, RideEvent] = (ride, event) =>
event match {
sealed trait RideEvent extends EntityEvent[Ride.ID]