This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Service extends Stoppable[Either[E, Unit]] { | |
def start(): Future[E, Unit] | |
def name: String | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Service | |
.withName("in-memory-cache") | |
.withFallibleStarter{ () => cache.loadAsync() : Future[Either[StartError, Unit]] } | |
.build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val akkaApplicationService: Service = builder | |
.startSystemDependent(SomeEtcdService()) | |
.thenStartHttp( | |
HttpServiceDefinition( | |
new AkkaControllers().routes, | |
serverConfig.host, | |
serverConfig.port, | |
serverConfig.hardDeadline, | |
serverConfig.unbindingDelay | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Service | |
.withName("topic-dependent") | |
.withFallibleStarter( () => | |
(for { | |
_ <- EitherT(KafkaAdmin().ensureTopicCreated("foobar-topic")) | |
_ <- EitherT.right[KafkaAdmin.TopicCreationFailed](consumer("foobar-topic")) | |
} yield ()).value | |
) | |
.build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed trait RideEvent extends EntityEvent[Ride.ID] |